Back up and copy a MYSQL database [figure] _ MySQL

Source: Internet
Author: User
Backing up and copying a MYSQL database [figure] it is important to back up the database when the table is lost or destroyed. If the system crashes, you can restore the table to the state at the time of crash, and do not lose data as much as possible. Likewise, users who mistakenly send the drop database or drop table command may request data recovery from you. Sometimes this is caused by the MySQL Administrator. the administrator tries to use an editor like vi or emacs to directly edit the table files and destroy them. This is definitely a bad thing for the table.

The two main methods for backing up a database are to use the mysqldump program or directly copy database files (for example, c p, tar, or c p I o ). Each method has its own advantages and disadvantages:

The mysqldump and MySQL server are used together for operations. The direct copy method is separated from the server. Therefore, measures must be taken to ensure that no client is modifying these tables during the copy process. This problem is the same as using file system backup to back up the database: If the database table is updated during File system backup, the table files to be backed up are in a different state, it is meaningless to restore the table in the future. The difference between file system backup and direct copy is that you have the right to control the backup progress for the latter, so you can take measures to ensure that the server keeps the table static.

Mysqldump is slower than direct copy.

Mysqldump generates text files that can be transplanted to other machines or even machines with different hardware structures. Directly copying files cannot be transplanted to other machines, unless the table to be copied uses the MyISAM storage format. An ISAM table can only be copied between machines with the same hardware structure. For example, copying files from s parc's Solaris machine to Intel's Solaris machine (or vice versa) won't work. The MyISAM table storage format introduced by MySQL3.23 solves this problem because it is independent from the machine. Therefore, if both of the following conditions are met, you can directly copy the file to a machine with different hardware structures: that is, the version of MySQL3.23 or later must be run on the other machine, and the file must be expressed as a MyISAM table instead of an ISAM table.

No matter which backup method you choose, there are some principles. you must stick to these principles to ensure the best results when you need to restore the database content:

Perform regular backup. Set a timetable and stick to it.

Tells the server to run the update log. Update logs are helpful when you need to recover the database after the crash. After using the backup file to restore the database to the status at the time of backup, you can run the query in the update log to re-run the backup and make changes. This operation restores the tables in the database to the state of crash. In the file system backup language, the database backup file indicates full dump, while the update log indicates incremental dump.

Use consistent and understandable backup file naming patterns. Such names as B a c k up 1 and backup2 have no special meaning. When you need it to restore, you have to waste time viewing the content in the file. You will find that using the database name and taking the time to construct the backup file name is advantageous. For example:

% Mysqldump samp_db>/usr/archives/mysql/samp_db. 2017-10-02

% Mysqldump menagerie>/usr/archives/mysql/menagerie.1999-10-02

You may need to compress the backup files after they are generated. After all, the backup files are large, so you may need to terminate the backup files to avoid them filling up the disk, which is similar to the termination log file. You can use the same technology to terminate backup files:

Use file system backup to back up your backup files. If you have suffered a complete crash, not only destroying the data directory but also destroying the disk drive that contains the database backup, it will cause real trouble. You should also back up the update log.

Place the backup file on a different file system from your database. This will reduce the possibility that the file system containing the data dictionary will be filled with backup files generated.

The technology for creating backups is also helpful for copying databases to another server. It is common to transfer a database to a server running on another host, but you can also transfer data to another server running on the same host. If you are running a server for a new version of MySQL and want to test it with some real data on the finished server, this may happen. Another possibility is that you get a new machine and want to move all the databases to the new machine.

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.