红联Linux门户
Linux帮助

Ubuntu下mysql不能显示中文解决方法

发布时间:2016-01-01 11:01:34来源:linux网站作者:草帽小子_DJ

问题:Ubuntu下mysql中文显示为?

查看字符集:

1.mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   |  latin1                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     |  latin1                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

然后修改配置:gedit /etc/mysql/my.cnf
找到[client]在下面加入
default-character-set=utf8
找到 [mysqld_safe]在下面加入
default-character-set=utf8
找到[mysqld]在下面加入
character-set-server=utf8
找到[mysql]在下面加入
default-character-set=utf8

改完后重新插入中文还是显示为?,这是因为你建立数据库时字符集已经设置为拉丁字符集了,删除数据库,重新建立数据库和表,在插入中文就可以正常显示了,此时的字符集为:
2.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/ |
+--------------------------+----------------------------+


linux mysql 5.5升级到5.6 使用MySQL的APT库:http://www.linuxdiyf.com/linux/16950.html

Ubuntu15.10 Kylin安装MySQL 5.7.9:http://www.linuxdiyf.com/linux/16137.html

Ubuntu下彻底卸载mysql:http://www.linuxdiyf.com/linux/16103.html

Ubuntu 15.10上将数据库MySQL转移到MariaDB:http://www.linuxdiyf.com/linux/16357.html

linux意外断电MySQL无法启动:http://www.linuxdiyf.com/linux/16508.html