How to fix Chinese garbled characters in mysqldump backup database

Source: Internet
Author: User
Tags mysql command line

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.