首先排查MySQL的字符集是否为UTF-8
通过命令
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/local/mysql-5.7.24-macos10.14-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.01 sec)
排除是mysql字符集的问题。
2.排除数据库的字符集问题
更改后依然无效。
更改表的字符集
alter table tb_user default character set utf8;
该命令用于将表tb_user的编码方式改为utf8;
更改后依然无效。
更改表的字段的字符集
alter table tb_user change username username varchar(20) character set utf8;
alter table tb_user change password password varchar(20) character set utf8;
alter table tb_user change gender gender char(1) character set utf8;
alter table tb_user change addr addr varchar(30) character set utf8;