日期:2014-05-16  浏览次数:20482 次

Ubuntu MySql 数据库编码设置
在mysql中默认字符集是latin1,
想要设置字符集为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/ |
+--------------------------+----------------------------+