This article summarizes the MySQL import and export data in Chinese garbled solution, the appearance of Chinese garbled general situation is imported when the encoding of the problem, as long as the code to adjust the consistency can solve this method, the following is a search to summarize some of the methods to facilitate the needs of friends.
in Linux systems
Linux defaults to UTF8 encoding, and Windows is GBK encoded, so the above garbled problem occurs.
Troubleshoot MySQL import and export data garbled problem
The first thing to do is to determine the encoding format of your exported data, you need to add--default-character-set=utf8 when using Mysqldump,
For example, the following code:
The code is as follows:
- - -- Default-character-set=utf8 dbname tablename > Bak.sql
You should also use--default-character-set=utf8 when importing data:
The code is as follows:
- - -- Default-character-set=utf8 dbname < Bak.sql
This unified coding solves the MySQL data migration garbled problem
I use Windows as the Export data source and import the MySQL library under the FreeBSD environment
Workaround:
Exporting data
First, MySQL is used as the export database source under the Windows platform. To view the system variables for character encoding:
The code is as follows:
MySQL> like '%char%'
See Character_set_database, this is latin1,latin1 is not loaded with multibyte character sets
Second, set the system variable to UTF8 under Windows
The code is as follows:
MySQL>set character_set_database=UTF8; # #设置默认的字符集为utf8
Third, export data
The code is as follows:
MySQL>Select*fromtable to OutFile ' C:table . txt' where + condition
At this time I exported some of the data I want, and the TXT file exists in the Table.txt.
Import data
Under the FreeBSD platform
One, the same set of character encoding system variables
The code is as follows:
MySQL> 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 | + ———————— –+ —————————-+ mysql>set Character_set_database=utf8; # #设置默认的字符集为utf8
second, reproduced data
The code is as follows:
MySQL>load data local infile '/home/table. txt' into Table ' table ';
At this point, the conditional data import and export, and processing the garbled situation.
In short, when two MySQL servers import and export, make sure that the character_set_database parameters of the two servers are the same, so as to prevent some garbled situation. Of course we can also use other character sets, such as GBK, to make adjustments. It operates as appropriate
Workaround three
Garbled resolution method
After importing the data, look at the command line to find the Chinese garbled
Use the following command to view the system character set
The code is as follows:
like ' char% ';
If it is not GBK or UTF8, stop the MySQL service and then modify the My.ini file to the installation directory,
Change the following variables in the file to the following, and if not, add the variables
The code is as follows:
[mysql] default - character - Set = [mysqld]character-set- Server=
Restart the service, re-import the data, if it is still garbled,
At the end of the experience, you just have to unify the import and export code.
[Turn]mysql Import and export Data Chinese garbled solution summary