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_name | Value |
---|---|
character_set_client | utf8mb4 |
character_set_connection | utf8mb4 |
character_set_database | utf8mb4 |
character_set_filesystem | binary |
character_set_results | utf8mb4 |
character_set_server | utf8mb4 |
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;