Mysql backup recovery (view, stored procedure) _ MySQL

Source: Internet
Author: User
Tags mysql backup
Mysql backup recovery (view, stored procedure) bitsCN.com

Mysql backup and restoration (views and stored procedures)

Recently, when I backed up and restored mysql, I found that the view was restored and an error occurred while creating the view. I checked the information online and found the following information:

1. if the backup database contains a view, you must change character-set in my. ini to latin1 to restore the view.

2. after restoration, change latin1 to gb2312. Otherwise, the stored procedure cannot be used.

3. the stored procedure cannot be backed up along with the database. for restoration of the stored procedure, you must manually copy the SQL statement and execute it in the QUERY.

I felt a little troublesome, so I looked for other methods. I backed up the mysql database using the following methods and then restored it. no error was reported and the view was restored:

# Restoring mysql backups in windows. you do not need to modify my. ini to restore the view (verified)

Mysqldump-uroot-p123 -- default-character-set = gbk -- opt -- extended-insert = false -- triggers-R -- hex-blob-x db_name> f:/db. SQL

Mysql-uroot-p123-f db_name <f:/db. SQL

Linux:

SQL to back up the MyISAM table:

/Usr/local/mysql/bin/mysqldump-uroot-p123 -- default-character-set = utf8 -- opt -- extended-insert = false -- triggers-R -- hex-blob-x db_name> db_name. SQL

Use the following SQL to back up the Innodb table:

/Usr/local/mysql/bin/mysqldump-uroot-p123 -- default-character-set = utf8 -- opt -- extended-insert = false -- triggers-R -- hex-blob -- single -transaction db_name> db_name. SQL

Parameter annotation:

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: The data exported by-c 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 to export data. if the data table does not use the default latin1 character set, this option must be specified during export, otherwise, garbled characters will occur after the data is imported again.

-- Disable-keys: tells 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. if you do not want to use it, set this option to false.

-- Hex-blob exports 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 submits a request before starting export 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 exports data, without adding the create table statement.

-- No-data,-d: only the database table structure is exported without exporting any data.

-- Opt 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.

-- Quick,-q this option is useful when exporting large tables. it forces mysqldump to directly output records from server queries rather than cache all records into memory.

-- Routines,-R: export stored procedures and user-defined functions.

-- Single-transaction: This option submits a begin SQL statement before exporting data. BEGIN does not block any applications and ensures database consistency during export. It is only applicable to transaction tables, such as InnoDB and BDB. This option and the -- lock-tables option are mutually exclusive, because lock tables will implicitly commit any pending transactions. To export a large table, use the -- quick option.

-- Triggers: export the trigger at the same time. This option is enabled by default. use -- skip-triggers to disable it.

BitsCN.com

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.