Use mysql command line to export SQL

Source: Internet
Author: User
Tags mysql command line


Using mysql command line to export SQL is actually very simple. You only need two steps. First, enter the mysql command line, enter the database name for use, and then enter source test. SQL can export all the data in the Test table. You can use mysqldump and source to export data at www.2cto.com: mysqldump-urott-P5678 -- default-character-set = gb2312-p-h127.0.0.1 Test test1> test1. SQL: 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: www.2cto.com can (under the mysql Command Line) mysql> use Test; mysql> source test1. SQL; if you use the select method to obtain files, you should import them as follows: mysql> l Oad data infile "test. SQL" into table Test. test1; you can view the import status in "show processlist \ G. 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 constraints, such: alter table cwealinfo drop foreign key 'xxx'; alternatively, set foreign_key_checks = 0; pay attention to the database version when exporting and importing data, for example, importing data from 4 to 5, it is best to use 4 mysqldump, 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.
 

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.