Win系统下MYSQL不能插入中文解决方法

September 23, 2018 默认分类

环境:wamp

在被各种方法误导之后终于成功了QAQ

1. 列表项目

左键点击windows右下角的wampserver图标,鼠标移到MySQL,在列表里找到my.ini并打开。

在以下三部分里添加如下内容:

[client] 
default-character-set = utf8mb4 
[mysql] 
default-character-set = utf8mb4 
[mysqld] 
character-set-client-handshake = FALSE 
character-set-server = utf8mb4 
collation-server = utf8mb4_unicode_ci 
init_connect=’SET NAMES utf8mb4’

2. 查看数据库变量

重启wampserver,执行查看数据库变量的sql语句:show variables like 'character%'

Variable_nameValue
character_set_clientutf8mb4
character_set_connectionutf8mb4
character_set_databaseutf8mb4
character_set_filesystembinary
character_set_resultsutf8mb4
character_set_serverutf8mb4

character_set_client,character_set_connection,character_set_database,character_set_results,character_set_server这五个变量的值是utf8mb4。

3. 将数据库转换为utf8mb4

sql语句为:ALTER DATABASE DATABASE_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

4. 将表转换为utf8mb4DATABASE

切换数据库:use DATABASE_NAME

sql语句为:ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

5. OKay

感谢:https://blog.csdn.net/X_Xian_/article/details/77648488


添加新评论