mysql插入记录字符中包含中文报错的问题解决方法
环境win10、mysql 5.5.55
我想这个方法除了在这个环境下,其他windows环境也可以尝试下。
一、准备工作
我是通过直接dos命令行窗口直接引入一个.sql文件的方式来进行创建表空间、创建表、和插入数据的。
下面来看看准备好的.sql文件
--创建表空间bbs create database bbs; use bbs; --使用bbs --创建一张表 create table article( id int primary key auto_increment, pid int, rootid int, title varchar(255), cont text, pdate datetime, isleaf int ); --插入语句 insert into article values(null,0,1,蚂蚁大战大象,蚂蚁大战大象,now(),1); insert into article values(null,1,1,大象被打趴下了,大象被打趴下了,now(),1); insert into article values(null,2,1,蚂蚁也不好过,蚂蚁也不好过,now(),0); insert into article values(null,2,1,瞎说,瞎说,now(),0); insert into article values(null,4,1,没有瞎说,没有瞎说,now(),0); insert into article values(null,1,1,怎么可能,怎么可能,now(),0); insert into article values(null,6,1,怎么没有可能,怎么没有可能,now(),1); insert into article values(null,6,1,可能性是很大的,可能性是很大的,now(),0); insert into article values(null,2,1,大象进医院了,大象进医院了,now(),1); insert into article values(null,9,1, 护士是蚂蚁,护士是蚂蚁,now(),0);
之后通过命令行 mysql> . C:UserslijinquanDesktoparticle.sql(注意.后是有空格隔开的)回车执行。
结果dos窗口提示
在百度中找了很多解决方法,比如将my.ini文件中的default-character-set=utf8改为default-character-set=utf8mb4,执行插入语句前先执行set names utf8
之类都没用。
之后改写插入语句中的中文为英文,如
竟然可以了。
但是为什么中文不行呢?utf8不是万国码吗?后来通过尝试终于得到了最终解决办法。
解决方法:
步骤一:我们首先要要将服务器关闭,步骤:进入“计算机管理”界面,再选“服务和应用程序”再选“服务”,在服务列表中找到Mysql鼠标右键单击,选“停止”
待停止进度条完成后mysql关闭成功。如下图:
步骤二:
通过修改my.ini文件中的default-character-set为GBK,下图画红圈区域
步骤三:
重启mysql,我们先插入一条语句试试
成功了。
这是在学习过程中遇到的一个关于Mysql的问题,顺手记录下,水平有限,不足之处请指出。