load data infile 中文乱码解决

系统配置linux
mysql 默认utf8
首先使用show variables like "%char%";
+--------------------------+-------------
| Variable_name | Value
+--------------------------+-------------
| character_set_client | gbk
| character_set_connection | gbk
| character_set_database | utf8
| character_set_filesystem | binary
| character_set_results | gbk
| character_set_server | utf8
| character_set_system | utf8

此时可以使用set names utf8;

再次使用show variables like "%char%";

+--------------------------+------------
| 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 | utf8
| character_set_system | utf8


各种字符参数统一为utf8时.
使用
mysql -uroot -p -Ne "set names utf8;select * from t_kernel where mootime<'2008-10-01 00:00:00'" league >kernel.log

来导出数据.
导出完成后,
使用
load data infile '/home/mysql/kernel.log' into table t_kernel;
导入数据.
这次导入的数据应该正确.

当时显示可能还是乱码.你可以通过设置set names gbk;来查看记录.是否正常.

你可能感兴趣的:(程序文章)