Use mysqldump and source
You can use this method to export data:
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 processlistG" 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 set issues. If the character sets of the two libraries are different, this may cause problems. Therefore, you 'd better use "show variables like % char %" to check whether you need to adjust character set settings before importing.