This article will introduce some solutions for using mysqldump to back up database Chinese garbled characters. Most of the causes of garbled characters are database encoding problems. If you encounter such problems, refer.
When mysql tool mysqldump is used to back up the database, if the character set on the MySQL server is latin1, the Chinese characters posted by mysqldump in the second world are garbled! A simple method is to add the default Character Set option when writing backup statements, such:
The Code is as follows: |
Copy code |
Mysqldump-h 127.0.0.1-P 3307-u username -- default-character-set = gbk-p databasename> dumpfile.txt |
-H host
-P port. This option must be used separately, but cannot be consecutively written after the host address.
-U User Name
-- When the default-character-set knows that the data content is Chinese, it can be specified as gbk, so that even if the database itself sets the character set to the Chinese language of the file latin1, it can be normal!
-P Password
Databasename Database Name
> The following is the path of the output file.
Garbled characters occur when mysql command line imports data
Sometimes, because the SQL data volume is large and you need to import data under the command line, garbled characters may occur in the imported data. Execute the following command to solve the problem:
The Code is as follows: |
Copy code |
1. use database; 2. set character set utf8; (eg: GBK) 3. source example. SQL (SQL file path) |
Summary import and export Chinese garbled characters
Summary
SQL garbled characters may indicate that the global encoding of the database is inconsistent with that of a database. You can add the encoding during export, and change it to utf8 or gbk.
The Code is as follows: |
Copy code |
Mysqldump-u username -- default-character-set = utf8-p Database Name> file path file name. SQL |