ubantu 下 mysql 不能输入中文解决办法

打开配置文件:sudo gedit /etc/mysql/my.cnf

在最下面添加:

[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8

保存

暂停mysql服务:sudo /etc/init.d/mysql stop

重启mysql服务:sudo /etc/init.d/mysql restart

登录mysql:sudo mysql -u root -p

查看字符串编码:show variables like '%char%';

如果结果显示:

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

则配置成功

 

你可能感兴趣的:(mysql)