Mysql Notes Data backup and restoration of the use of detailed _mysql

Source: Internet
Author: User

The data is very important, this point with toes to know, in order to ensure data security, so the need to regularly backup data

Let's write a few notes about data backup and restore

Data backup

Backing up a database using the mysqldump command

Mysqldump-u username-p dbname table1 table2...>backupname.sql

Where dbname represents the database name, table1 and table2 represent the name of the table, without which the entire database is backed up

The Backupname.sql parameter represents the name of the backup file, which can be preceded by an absolute path

It is important to note that only the tables in the database are backed up, and if you want to restore you must restore them in the existing database

tips: Typically, the suffix for a backup file is. sql, which can also be. txt, but not professional

Backing up multiple databases using the mysqldump command

mysqldump-u username-p --databases dbname1 dbname2...>backupname.sql 

Here--databases means to back up multiple databases, followed by the database name

In addition, you can back up all databases

Backing up all databases using the mysqldump command

mysqldump-u username-p - -all-databases>backupname.sql 

Copy the entire database directory directly

Replicating the database directory directly is the easiest way to backup, but not the best

When using this method, the database service needs to be temporarily stopped in order to avoid data changes, but is not allowed in practice

Also, this method does not apply to the tables of the InnoDB storage engine, which is more convenient for the tables of the MyISAM storage engine

Data restore

Restore using the MySQL command

-P[dbname]<backup.sql    

[dbname] is optional if you use the--all-databases parameter to back up the entire database instead of backing up the table individually

Then you can not use the dbname parameter

Copy directly to the database directory

You must ensure that the major version number of the database is consistent in this way

Usually effective for myisam, not suitable for InnoDB

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.