MySQL5.7插入中文乱码
参考:
https://blog.csdn.net/kelay06/article/details/60870138
https://blog.csdn.net/itmr_liu/article/details/80851266
Mysql5.7插入中文乱码,通过在命令行修改发现不行,每次数据库重启以后还是原来的样子,所以采用以下方式解决问题:
1、打开my.ini文件,我的在:C:\ProgramData\MySQL\MySQL Server 5.7\ 下
[client]
# pipe=
# socket=MYSQL
port=3306
##添加下面行
default-character-set=utf8mb4
[mysql]
no-beep
# default-character-set=
##添加下面行
default-character-set=utf8mb4
[mysqld]
# character-set-server=
##添加下面4行
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
然后重启mysql即可
Windows可在服务管理器中操作,也可使用命令行(cmd):
net stop mysql 回车
net start mysql 回车
然后连接mysql,
mysql -u root -p
->#输入数据库密码 回车
->show variables like 'character%';
+--------------------------+----------------------------------------------------------------------------+
| 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 | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | I:\Apache\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+----------------------------------------------------------------------------+
发现已经改过来了,再次插入中文:
发现不乱码了