Background
Need to make MySQL data synchronization, from a server to synchronize the database to another server, if you toss over, you know there is this thing--mysqldump, in fact, is a command of MySQL comes from
Operation Step 1. Meet Mysqldump
is generally MySQL installation directory/bin/, the command is also simple can be viewed through the mysqldump--help
2. Exporting SQL
/mysql/bin/mysqldump -u${username} -p${password} -h ${host} -P ${port} --quick -d ${database_name} --skip-lock-tables > ${database_name}.sql
Replace the ${} with the desired value
The above statement means to say database_name This library is exported to Database_name.sql
and due to the addition of-D only the table structure is exported
3. Import SQL
/mysql/bin/mysql -u${username} -p${password} --database ${database_name} < ${database_name}.sql
Replace the ${} with the desired value
4. Think about the time when many libraries need to be dealt with.
Written in the form of a script, the idea is as follows:
- Organize the library names of the libraries you want to export into a TXT file, one library for each behavior;
- By traversing the files in 1 and then executing the command to export SQL one by one;
- Then, by traversing the TXT file in 1, execute the command to import SQL one by one;
The specific script is as follows:
Off Topic
In fact, a lot of SQL Visualizer support Export import function, hahaha, in fact, very useful, but it is possible to deal with a large amount of data when inconvenient, use what efficiency is the most positive use is what, of course, the premise is your script will also, is not it?
Simple use of mysqldump