ubuntu16.04 mysql5.7.20表中插入中文显示???的解决方法

时间:2021-11-17 06:30:55

Ubuntu16.04下安装mysql:

sudo apt-get install mysql-server mysql-client


打开配置文件: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)


则配置成功