查看mysql数据库当前编码
mysql -uroot -pxxx
use tigercity;
show variables like ‘character_set_database‘;或者
MariaDB [lottery]> show variables like ‘character_set_database‘;
+------------------------+--------+
| Variable_name | Value |
+------------------------+--------+
| character_set_database | latin1 |
+------------------------+--------+
1 row in set (0.01 sec)
show variables like ‘character_set_%‘ 通配符匹配
MariaDB [lottery]> show variables like ‘character_set_%‘;
+--------------------------+----------------------------------+
| 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/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
修改编码方法一、
alter database lottery character set utf8;
即时生效,再次show variables like ‘character_set_database‘;
方法二、
vim /etc/my.cnf
[mysqld]
character_set_database=utf8
character_set_server=utf8
然后重启mysql服务
service mysqld restart