Ubuntu mysql 插入中文出错问题

首先停止MySQL服务:sudo /etc/init.d/mysql stop

然后编辑MySQL配置文件:sudo gedit /etc/mysql/my.cnf

在my.cnf文件中的[client]段下面加入

default-character-set=utf8
[mysqld_safe]
default-character-set=utf8
[mysqld]
default-character-set=utf8
[mysql]
default-character-set=utf8

重新启动MySQL服务,

sudo /etc/init.d/mysql start

进入MySQL的命令提示符下输入如下指令:

mysql>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/

然后把原来的数据库删了,再新建(我就是这样做的,不这样做还是会出错)

现在中文数据能够插入了

成功

你可能感兴趣的:(学习)