How to export and import a Chinese table from mysql

Source: Internet
Author: User

Mysql is often used in the development process to export and import Chinese tables. This article will detail how to use it. If you need it, refer
1. Export data for utf8 first:
(1) Export all tables of the source database:
Copy codeThe Code is as follows:
Mysqldump-u root-p password -- socket = mysql. sock -- default-character-set = utf8 -- set-charset = utf8 -- hex-blob -- databases Database Name> utf8. SQL

(2) modify the SQL file and delete the database creation commands contained in the file header.
(3) log on to the target database
Mysql-uroot-p password -- default-character-set = utf8 -- socket = mysql. sock-
Note: You must specify the character set to log on. In addition, the specified character set must be consistent with the character set specified during export.
(4) Delete A database (if any)
Drop database name;
(5) Create a database, save it as utf8 storage format, and import
Copy codeThe Code is as follows:
Create database name charset = utf8;
Use Database Name;
Source utf8. SQL;

After this item is imported, Chinese tables may contain garbled characters. Therefore, use the following method to import a Chinese table.

Ii. Export and Import a Chinese table:
Copy codeThe Code is as follows:
# Export
Mysqldump-u root-p password -- socket = mysql. sock -- default-character-set = gbk -- set-charset = gbk -- hex-blob database name table name 1 Table name 2 ...... > Gbk. SQL
# Import (if the table already exists, it will be deleted before being imported. Therefore, you do not need to delete the existing table in advance)
Mysql-uroot-p password -- default-character-set = gbk -- socket = mysql. sock-A <EOF
Use Database Name;
Source gbk. SQL
EOF

Related Article

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.