How to recover data and restore data with mysqldump

Source: Internet
Author: User

1. Backup:
    • Write a script:
!/bin/bash` echo ‘dump begin‘ Now=$(date +%d-%m-%Y--%H:%M:%S) //获取当前时间 File=backup-$Now.sql.gz //组成文件名 mysqldump -u zc_test -pzc_test2016 -h test.rtdream.com --port 3307 --all-databases  --single-transaction --routines --add-drop-table --quick --default-character-set=utf8  --flush-privileges | gzip > /root/mysql_backup/$File echo ‘dump end‘
    • Among the mysqldump parameters:
    • -his the hostname to be connected
    • -pis the port to connect to
    • --all-databasesIndicates that all databases are backed up
    • --single-transactionis to send a BEGIN command before dump, if it is not possible to add an error:mysqldump: Got error: 1142: SELECT,LOCK TABL command denied to user ‘XXXXXX‘@‘XXXXXX‘ for table ‘XXXXXX‘ when using LOCK TABLES‘
    • --routinesInstructions for backup procedures and functions
    • --add-drop-tableAdd a drop table in front of each create table
    • --default-character-set=utf8When backing up the data encoded with UTF8, it is said that there will be a coding error when the view is not restored
    • --flush-privilegesTo back up a database named MySQL with the Refresh permission command
    • --quick mysqldumpYou can retrieve and dump table content by row, or you can retrieve the entire contents of a table and buffer the content in memory before dumping. If you are dump a large table, there may be a problem in the buffer. The--quick option forces the contents of the table to be retrieved and dumped on rows without first buffering the content
    • | gzipis to compress the content directly.
2. Restore Backup
    • command line into MySQL:mysql -u root -p
    • ' Source ' Your backup file path ' * (note that the MySQL version of the backup is the same as the original, the original 5.7 is now 5.7, otherwise prone to problems) *

How to recover data and restore data with mysqldump

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.