问题:
Incorrect string value: '\xE6\xB2\x99\xE6\xB2\xB3' for column 'name' at row 1
解决:
在mysql中输入:
show variables like "char%";
查看mysql的编码方式:
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
标红的那两行是问题的关键。
修改配置文件:
sudo nano /etc/mysql/conf.d/mysql.cnf
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
按Ctrl+o保存,在按ctrl+x退出
重启mysql服务:
sudo systemctl restart 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/ |
+--------------------------+----------------------------+
这样就OK了,但是原来创建的数据库和表还是不支持的,需要重新创建。做好数据的备份。