Use the mysql command line to export SQL _MySQL

Source: Internet
Author: User
Use the mysql command line to export SQL bitsCN.com


Use mysql command line to export SQL

In fact, it is very simple. you only need two steps to first enter the mysql command line, enter the use database name, and then enter source test. SQL to export all the data in the Test table.

You can use mysqldump and source to export data in this way:

Mysqldump-urott-P5678 -- default-character-set = gb2312-p-h127.0.0.1 Test test1> test1. SQL

You can also do this:

Mysql-uroot-P5678 -- default-character-set = gb2312-p-h127.0.0.1-e "select * from Test. test1 "> test1. SQL (however, to manually create a table, you can use show create test1 to obtain the table creation statement)

Import:

Yes (in the mysql command line)

Mysql> use Test;

Mysql> source test1. SQL;

If you use the select method to obtain the file, you should import it as follows:

Mysql> load data infile "test. SQL" into table Test. test1;

You can view the import status in "show processlist/G" during import.

Sometimes an ERROR occurs: ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails ('test/test1 ', CONSTRAINT 'XXX' foreign key ('A') REFERENCES 'BB' ('A '))

In this case, you need to delete the foreign key constraint, for example:

Alter table cwealinfo drop foreign key 'XXX ';

Alternatively, set foreign_key_checks = 0;

When exporting and importing data, pay attention to the database version. for example, if you export data from 4 to 5, you 'd better use mysqldump of 4. Otherwise, it may fail. In addition, you also need to pay attention to character sets. if the character sets of the two libraries are different, this may cause problems, therefore, we recommend that you use "show variables like '% char %'" to check whether you need to adjust character set settings before importing.

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.