解决mysql中文数据库乱码

时间:2021-11-01 02:02:21

最终解决办法:

1.打开mysql配置文件my.in

2.在[client]节点下添加default-character-set=utf8
3.在[mysqld]节点下添加character-set-server=utf8 collation-server=utf8_general_ci

4.重启mysql

5.使用mysql> show variables like 'char%';查询修改是否生效,结果应该如下:

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 | /opt/mysql-cluster/share/mysql/charsets/ |
+--------------------------+------------------------------------------+
8 rows in set (0.00 sec)

6.将已经创建好的数据库和表改为utf8:

ALTER DATABASE `数据库` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
ALTER TABLE `数据表` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

 

最终结果:已经存在的表中的数据依然是问号?,新插入的数据可以显示中文,新建的数据库和表都可以显示中文,问题基本解决