想要设置字符集为uft-8,可以在 my.cnf 文件中添加以下设置:
执行:
sudo gedit /etc/MysqL/my.cnf
设置:
·[client] default-character-set=utf8 ·[MysqLd] default-character-set=utf8 skip-character-set-client-handshake #此处是忽略客户端的字符集,使用服务器的设置
(skip语句和client中的default选一个)
当然你可以在建立数据库是规定字符集:
create database db_name default character set utf8 callate utf8-general-ci;
也可以在链接数据库前设置:set names 'utf8';
重点在红字上,加了skip-character-set-client-handshake,client里面就不用加default了
重启MysqL
sudo /etc/init.d/MysqL restart
执行
show variables like 'characte%';
结果:
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/MysqL/charsets/ | +--------------------------+----------------------------+原文链接:https://www.f2er.com/ubuntu/355563.html