Mysql command line restore the SQL file exported by phpMyAdmin with Chinese characters _ MySQL

Source: Internet
Author: User
Use the mysql command line to restore the phpMyAdmin exported SQL file containing Chinese characters.

BitsCN.com recently obtained a MySQL script file of dozens of MB, ready to be restored to the database.

I used MySQL-Front for a short time. I tried it first and the result was suspended.

In this case, create an empty database with MySQL-Front and use the mysql command line to import the database.

1) an empty database is created using MySQL-Front.

Because all objects in the script have default charset = gbk COMMENT =... Command, so select gbk for the character set

2) start MySQL command line and enter the password

3) use the new database B

Enter the command: use B;

4) changing the file reading character set to utf8 is critical.

Start with default charset = gbk COMMENT =... To set it to gbk, the following command is used:

Set names gbk;

However, during import, all errors are caused and Chinese characters cannot be recognized.

Later I realized that it should be set to the character set of the SQL file itself. what is the character set of the SQL file itself?

My method is to open the file with VS.net IDE, save it as, and select "save encoding"

The character set is UTF-8;

So

Enter the command: set names utf8; note that it is not set names UTF-8;

5) import files

Enter the command: source file path;

Soon, the file is successfully imported into the database, which is highly efficient.

Go to MySQL-Front and check that the data is imported normally!

BitsCN.com

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.