MySQL backup and recovery _ MySQL

Source: Internet
Author: User
Tags types of tables mysql backup
MySQL backup and recovery discusses MySQL backup and recovery mechanisms, and how to maintain data tables, including the two main types of tables: MyISAM and Innodb. the MySQL version is 5.0.22.

This article describes how to use a free backup tool provided by MySQL for backup. of course, you can choose a more convenient third-party tool to back up and restore the MySql database.

Currently, MySQL supports the following free BACKUP tools: mysqldump and mysqlhotcopy. you can also use SQL syntax to back up: BACKUP TABLE or Select INTO OUTFILE, or back up binary logs (binlog ), you can also directly copy data files and related configuration files. MyISAM tables are saved as files, so they are relatively easy to back up. the methods mentioned above can be used. All Innodb tables are stored in the same data file ibdata1 (multiple files or independent tablespace files), which is relatively difficult to back up, the free solution can be copying data files, backing up binlogs, or using mysqldump.

1. mysqldump

1.1 Backup

Mysqldump adopts an SQL-level backup mechanism. it imports data tables into SQL script files and is suitable for upgrading between different MySQL versions. this is also the most common backup method.

Here are some main parameters of mysqldump:

-- Compatible = name

It tells mysqldump that the exported data will be compatible with the database or the old MySQL server. The values can be ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_tables_options, and no_field_options. separate them with commas. Of course, it does not guarantee full compatibility, but is as compatible as possible.

-- Complete-insert,-c

The exported data adopts the complete Insert method containing the field name, that is, all values are written in one row. This can improve the insertion efficiency, but may be affected by the max_allowed_packet parameter, resulting in insertion failure. Therefore, you need to use this parameter with caution. at least I do not recommend this parameter.

-- Default-character-set = charset

Specifies the character set used for data export. if the data table does not use the default latin1 character set, this option must be specified during data export. otherwise, garbled characters will occur after data is imported again.

-- Disable-keys

Tell mysqldump to add/* at the beginning and end of the Insert statement /*! 40000 Alter TABLE table disable keys */; and /*! 40000 Alter TABLE table enable keys */; statement, which greatly improves the speed of the insert statement because it re-creates the index after all data is inserted. This option is only applicable to MyISAM tables.

-- Extended-insert = true | false

By default, mysqldump enables the -- complete-insert mode, so if you do not want to use it, use this option to set its value to false.

-- Hex-blob

Export binary string fields in hexadecimal format. This option is required if binary data exists. The affected field types include BINARY, VARBINARY, and BLOB.

-- Lock-all-tables,-x

Before starting the export, submit a request to lock all tables in all databases to ensure data consistency. This is a global read lock and the -- single-transaction and -- lock-tables options are automatically disabled.

-- Lock-tables

It is similar to -- lock-all-tables, but instead of locking all tables in the database. This option is only applicable to MyISAM tables. for Innodb tables, you can use the -- single-transaction option.

-- No-create-info,-t

Only export data without adding the Create TABLE statement.

-- No-data,-d

Only the database table structure is exported without exporting any data.

-- Opt

This is just a quick option, it is equivalent to adding the -- add-drop-tables -- add-locking -- create-option -- disable-keys -- extended-insert -- lock-tables -- quick -- set-charset option at the same time. This option allows mysqldump to export data quickly and export data back quickly. This option is enabled by default, but can be disabled with -- skip-opt. Note: If the -- quick or -- opt option is not specified when running mysqldump, the entire result set is stored in the memory. If you export a large database, problems may occur.

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.