Home>Article>Database> Detailed explanation of examples of using mysqldump to back up and restore tables

Detailed explanation of examples of using mysqldump to back up and restore tables

Y2J
Y2J Original
2017-05-23 15:07:41 1655browse

The code is as follows:

mysqldump -u user -p db tab1 tab2 > db.sql

Restore

The code is as follows:

mysql -u user -p db < db.sql

Reference:

1. Copy files : : (Guarantee database Directly copying files without writing operations (can lock the table) cannot be transplanted to other machines, unless the table you are copying uses the MyISAM storage format
2.mysqldump : mysqldump generates a text file that can be transplanted to other machines

Example:
Backup the entire database --> mysqldump db1 >/backup/db1.20060725
Compressed backup --> mysqldump db1 | gzip >/backup/db1.2006 0725
Split table backup --> mysqldump db1 tab1 tab2 >/backup/db1_tab1_tab2.sql
Direct remote backup --> mysqladmin -h boa.snake.net create db1
mysqldump db1 | mysql -h boa.snake.net db1

Copy the backup table     —>   cp tab.*  backup/


Restore
Reinstall the database with the latest backup file. If you use the file generated by mysqldump, use it as input to mysql. If you are using files copied directly from the database, copy them directly back to the database directory. However, in this case you will need to close the database and then restart it before copying the files.

【Related Recommendations】

1.Mysql free video tutorial

2.Example tutorial on processing special sql statements in mysql

3.Detailed explanation of how to write SQL statements to delete tables in different databases

4.Teach you how to run multiple MySQL services on one machine

5.Small Mysql database backup script without virtual host

The above is the detailed content of Detailed explanation of examples of using mysqldump to back up and restore tables. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn