[Turn] garbled MySQL import data analysis and solution

mysql> select * from table into outfile 'c: \ table.txt' where condition
(or selet * into outfile from table where condition)
guided by the Chinese data is garbled situation. Use
mysql> load data local infile 'c : \\ table.txt' into table `table`
inserted data will be garbled situation.
The reason for this is the mysql server system variables character_set_database the default character set issues
.
Common mysql5.1 Chinese manual 13.2.5. LOAD DATA INFILE syntax
......
character sets, indicated by character_set_database system variable is used to interpret the file. SET NAMES
and character_set_client settings will not affect the interpretation of input.
......
My solution:

First of all windows platform as a source of export mysql database

MySQL> Show Variables like '% char%';

+ ----------- + -------------------------- + -----------------
| variable_name | Value |
+ -------------------------- + ---------------------------- +
| character_set_client | latin1 |
| the character_set_connection | latin1 |
| the character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | GBK |
| character_set_system | utf8 |
| character_sets_dir | D: \ MySQL \ report this content share \ charsets \ |
+ --------------------- ----- + ---------------------------- +
view character_set_database, here is latin1, latin1 is not installed large character sets
mysql> set character_set_database = utf8; ## to set the default character set utf8
mysql> select * from table into outfile 'c:\table.txt' where 条件

In freebsd platform

mysql> show variables like '%char%';

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | gbk |
| character_set_system | utf8 |
|
+--------------------------+----------------------------+
同样显示latin1

mysql> set character_set_database = utf8; ## to set the default character set UTF8
MySQL> Load Data local INFILE '/home/table.txt' `table` INTO Table;

The View can!
Here character_set_database parameter is preferably the same as two servers, of course, we can also use other character sets gbk be adjusted, see the situation
define the default character set encoding the following format:
mysqldump.exe -u XXX-character- -ppass --default set = utf8 freshbug_database> fb_dat_utf8.sql

 

http://blog.chinaunix.net/uid-20161869-id-1974014.html

Reproduced in: https: //www.cnblogs.com/kiwi/archive/2012/11/29/2793877.html

Guess you like

Origin blog.csdn.net/weixin_34252090/article/details/94125756
Recommended