MySQL Backup and restore common commands

Source: Internet
Author: User
Tags bz2 compact mysql backup

1.3. MySQL Backup and Recovery

1. MySQL Backup

# mysqldump-uroot-pqweasd-s /data/3307/mysql.sock DB8 >/backup/3307-db8.sql

# mysqldump-uroot-pqweasd-s/data/3307/mysql.sock db8 >/backup/3307-db8_ $ (date +%f) . SQL

# mysqldump-uroot-pqweasd-s/data/3307/mysql.sock DB8 |bzip2 >/backup/3307-db8_$ (Date +%f). sql. bz2

# mysqldump-uroot-pqweasd-s/data/3307/mysql.sock DB8 |gzip >/backup/3307-db8_$ (Date +%f). sql. GZ

# MYSQLDUMP-UROOT-PQWEASD --default-character-set=utf8 -s/data/3307/mysql.sock DB8 >/backup/3307-db8 -utf8 _$ (Date +%f). SQL

# mysqldump-uroot-pqweasd--default-character-set=utf8-s/data/3307/mysql.sock DB8 |bzip2 >/backup/3307-db8-utf8_$ (Date +%f). sql. bz2

Backup tables, multiple tables

# MYSQLDUMP-UROOT-PQWEASD--default-character-set=utf8-s/data/3307/mysql.sock MySQL user >/backup/ Mysql_user -utf8_$ (Date +%f). SQL

# mysqldump-uroot-pqweasd--default-character-set=utf8-s/data/3307/mysql.sock MySQL User Host >/backup/mysql _user_host -utf8_$ (Date +%f). SQL

-B recovery creates the database and enters the created database, no-b. If the library to be recovered is deleted, it is not possible to recover the restored library if it needs to be recreated

# MYSQLDUMP-UROOT-PQWEASD--default-character-set=utf8-s/data/3307/mysql.sock - b DB8 >/backup/3307-db8 - b -utf8_$ (Date +%f). SQL

-B Backing up multiple library restores creates a database and enters the created database

# Mysql-uroot- Pqweasd-s/data/3307/mysql.sock-b DB8 DB9 | bzip2 >/backup/3307- DB8-DB9 -B_$ (date +%f). sql.bz2

# MYSQL-UROOT-PQWEASD --default-character-set=utf8 -s/data/3307/mysql.sock-b DB8 db9|bzip2 >/backup/3307-db8-db9-b- UTF8 _$ (Date +%f). sql.bz2

-D backing up the database structure (no data included)

# MYSQLDUMP-UROOT-PQWEASD--default-character-set=utf8-s/data/3307/mysql.sock - D DB8 >/backup/db8 - D -utf8_$ (Date +%f). SQL

--compact make backup the output more concise, less backup results some default options and various comments

# MYSQLDUMP-UROOT-PQWEASD --compact -s/data/3307/mysql.sock DB8 >/backup/3307-db8.sql

# MYSQLDUMP-UROOT-PQWEASD--default-character-set=utf8 --compact -s/data/3307/mysql.sock-d DB8 >/backup/db8-d-utf8_$ (Date +%f). SQL

2. MySQL Recovery

mysql> SOURCE/BACKUP/3307-DB8 - b -utf8_2018-05-12.sql;

When you do not have the use DB Word in the SQL file, you will need to specify the database name when importing

# mysql-uroot-pqweasd-s/data/3307/mysql.sock DB8 </backup/3307-db8_2018-05-12.sql


MySQL Backup and restore common commands

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.