mysql 在linux客户端插入数据中文乱码

1、查看系统客户端,数据库,连接层的编码

 查看方法: http://daizj.iteye.com/blog/2174993

进入mysql,通过如下命令查看数据库编码方式: 

mysql>  show variables like 'character_set_%'; 
+--------------------------+----------------------------------------+ 
| Variable_name            | Value                                  | 
+--------------------------+----------------------------------------+ 
| character_set_client     | latin1                                 | 
| character_set_connection | latin1                                 | 
| character_set_database   | utf8                                   | 
| character_set_filesystem | binary                                 | 
| character_set_results    | latin1                                 | 
| character_set_server     | latin1                                 | 
| character_set_system     | utf8                                   | 
| character_sets_dir       | /opt/mysql_root/base/share/charsets/ | 

 

从上面可以看出客户端,连接层都为latin1编码,数据库为utf8编码

执行下面命令,将字符编码为utf8

mysql>  SET NAMES 'utf8';

它相当于以下三指令:

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

再执行插入语句,结果正常入库

你可能感兴趣的:(mysql,中文乱码)