查看字符集:
方法一:show variables like ‘%character%‘;
方法二:show variables like ‘collation%‘;
设置字符集:
/*建立连接使用的编码*/
set character_set_connection=utf8;
/*数据库的编码*/
set character_set_database=utf8;
/*结果集的编码*/
set character_set_results=utf8;
/*数据库服务器的编码*/
set character_set_server=utf8;
set character_set_system=utf8;
set collation_connection=utf8;
set collation_database=utf8;
set collation_server=utf8;
设置完成后, 重启mysql字符集又失效了:
vim /etc/my.cnf文件:
在[mysqld]里面添加 character-set-server=utf8
重启mysql:
service mysqld restart