Ubuntu 下MySQL中文乱码的解决

 在/etc/my.cnf文件中加上以下两行内容:
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
注意,这个文件不一定存在,需将 /安装原文件/support-files/my-medium.cnf 复制到/etc/下,重命名

需重启mysql
停用:sudo /usr/local/mysql/bin/mysqladmin shutdown
启用sudo /usr/local/mysql/bin/mysqld_safe -user=mysql &

查看mysql编码
启用后sudo /usr/local/mysql/bin/mysql
mysql>show variables like 'character%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

注意,这样改变后原先所建数据库似乎不能用(不确定),尽量备份

新建数据库,就不会有乱码了。

 

http://www.lpi-china.org/bbs/viewthread.php?tid=3219

你可能感兴趣的:(linux)