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