【Mysql】统一字符编码(不能显示中文解决方法)
统一字符编码
- 登录后 \s 查看字符编码
- 在mysql目录下复制my-default.ini, 重命名为 my.ini 文件(linux /etc/my.cnf.d)
- my.ini中写入以下文件:
LINUX
sed -r '/^\[mysqld\]$/a\init_connect="SET collation_connection = utf8_unicode_ci"' /etc/my.cnf
sed -r '/SET collation_connection/a\init_connect="SET NAMES utf8""' /etc/my.cnf
sed -r '/SET NAMES utf8/a\character-set-server=utf8' /etc/my.cnf
sed -r '/character-set-server=utf8/a\collation-server=utf8_unicode_ci' /etc/my.cnf
sed -r '/collation-server=utf8_unicode_ci/a\skip-character-set-client-handshake /etc/my.cnf
echo '
[client]
default-character-set=utf8
' >> /etc/my.cnf.d/client.cnf
echo '
[mysql]
default-character-set=utf8
' >> /etc/my.cnf.d/mysql-clients.cnf
systemctl restart mysqld
WINDOWS
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
user=”root”
passwork=””
重启服务
net stop MySQL
net start MySQL