MySQL Database copy

Source: Internet
Author: User
Tags mysql command line

We often have this need to replicate the MySQL database on one server to other machines, such as a database migration.    The simplest way to do this is to use the off-the-shelf tools provided by MySQL: Mysqldump.    When using mysqldump, you need to specify the account, password, host and other information. For example: Mysqldump-h 10.10.8.12-u backup-p 6071-p backup_db >backup_db.mysql above command to save 10.10.8.12 host backup_db database in Backu The P_db.mysql file. -U backup indicates username. -P 6071 indicates port. -p means password, here we use the command line input, so here password is blank.

BACKUP_DB is the name of the database we want to replicate. After running this command we will get the Backup_db.mysql file. This file is actually the redirected file of the mysqldump output.

In this file, the MySQL statement required to replicate the database is saved.

We then copy the file to the target machine we want to copy to, and then go to the MySQL command line. Enter a database, and then run the source Backup_db.mysql to complete the replication of the database.

When you're done, you'll find that the fact that you're copying a database is that you run some column SQL statements, and Mysqldump does the job of exporting the contents of the database as SQL statements.

Another point to note is that you may encounter the following issues when Mysqldump: Mysqldump:got error:1044:access denied for user ' backup ' @ ' 10.10.4.42 ' to database ' Backup ' When using LOCK TABLES This problem occurs because mysqldump attempts to lock the entire table. This problem can be solved simply by adding the--skip-lock-tables option.

MySQL Database copy

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.