3,通过sqlyog远程工具操作,在Query窗口执行如下命令: SET NAMES utf8; INSERT INTO t SELECT 3 AS a ,‘第二梦‘ AS b; 是成功的,执行界面显示如下: 2 queries executed, 2 success, 0 errors, 0 warnings
Query: set names utf8
0 row(s) affected
Execution Time : 0 sec Transfer Time : 0 sec Total Time : 0.001 sec --------------------------------------------------
Query: insert into t select 3 as a ,‘第二梦‘ as b
1 row(s) affected
Execution Time : 0.002 sec Transfer Time : 0 sec Total Time : 0.002 sec
在sqlyog窗口查询t表,也正常显示中文字符,如下图所示:
但是在linux后面使用mysql窗口命令登录,还是乱码,如下所示:
mysql> SELECT * FROM t; +---+-----------+ | a | b | +---+-----------+ | 1 | bb | | 1 | ?? | | 2 | 骞村. | | 3 | 绗.?姊?| +---+-----------+ 4 rows in set (0.00 sec)
然后重启linux,重启mysql,或者export LANG="zh_CN.UTF-8"; [root@data01 ~]# service mysqld5612 restart Shutting down MySQL......... SUCCESS! Starting MySQL..................................................................... SUCCESS! [root@data01 ~]#
5,测试,为了数据统一,linux重新设置字符集,然后重新登录执行中文录入操作,所以表drop后create,还是报错,录入不了中文进去,编码问题 mysql> INSERT INTO t SELECT 4 AS a ,‘第四梦‘ AS b; ERROR 1366 (HY000): Incorrect string value: ‘\xB5\xDA\xCB\xC4\xC3\xCE‘ for column ‘b‘ at row 1 mysql> 但是使用sqlyog可以录入的,但是在linux的mysql操作窗口查询任然乱码,如下: mysql> SELECT * FROM t; +------+-----------+ | a | b | +------+-----------+ | 3 | 绗.?姊?| +------+-----------+ 1 row in set (0.00 sec)