MySQL database backup common sense, have to read

Source: Internet
Author: User
Tags sql error
The following articles mainly introduce the knowledge of MySQL database backup. When we perform operations on the MySQL database, it is inevitable that some data may be lost due to incorrect operations, mySQL database backup can help you avoid data loss or other database problems caused by various reasons. I. Data Backup shortcuts because this method is not officially available

The following articles mainly introduce the knowledge of MySQL database backup. When we perform operations on the MySQL database, it is inevitable that some data may be lost due to incorrect operations, mySQL database backup can help you avoid data loss or other database problems caused by various reasons. I. Data Backup shortcuts because this method is not officially available

The following articles mainly introduce the knowledge of MySQL database backup. When we perform operations on the MySQL database, it is inevitable that some data may be lost due to incorrect operations, mySQL database backup can help you avoid data loss or other database problems caused by various reasons.

I. Data Backup shortcuts

Because this method has not been verified in the official documentation, we call it a test.

Objective: To back up a MySQL database in the hostA host and restore it to the hostB

Test environment:

Operating System: WinNT4.0, Mysql3.22.34, and phpMyAdmin 2.1.0

Install MySQL database backup in hostA and create TestA Database

MySQL database backup is installed on the hostB, and no TestA database exists.

Procedure:

Start phpMyAdmin to check the database list in HostA and HostB. No TestA database exists in HostB.

Find the installation directory of MySQL database backup in HostA, and find the database directory data

In my test environment, the directory is C: \ mysql \ data

Find the subdirectory C: \ mysql \ data \ TestA of the corresponding database name

Paste and copy the file to the Data directory of HostB, which is the same as that of the backup Data directory of the HostB MySQL database.

Refresh the phpMyAdmin of HostB and check the database list. We can see that TestA has appeared, and the query and modification operations are normal. The Backup recovery is successful.

Test conclusion: MySQL databases can be stored in the form of files, backup, recovery as long as the corresponding file directory can be restored, no need to use other tools to back up.

Ii. Formal method (officially recommended ):

Export the mysqldump tool that uses MySQL database backup. The basic usage is:

Mysqldump [OPTIONS] database [tables]

If you do not specify any tables, the entire database will be exported.

Run mysqldump help to obtain the option table supported by your mysqldump version.

Note: If you run mysqldump without the quick or opt option, mysqldump loads the entire result set to the memory before the export result. If you are exporting a large database, this may be a problem.

Mysqldump supports the following options:

Add-locks

Add lock tables and unlock table before each TABLE is exported. (To make it faster to insert data to the MySQL database for backup ).

Add-drop-table

Add a drop table before each create statement.

Allow-keywords

Names of columns allowed to be created as keywords. This is done by adding the table name before the column name.

-C, complete-insert

Use the complete insert Statement (with the column name ).

-C, compress

If both the client and server support compression, all information is compressed between the two.

Delayed

Use the insert delayed command to INSERT rows.

-E, extended-insert

Use the new multiline INSERT syntax. (A more compact and faster insert statement is provided)

-#, Debug [= option_string]

Tracking Program usage (for debugging ).

Help

Displays a help message and exits.

 
 
  1. fields-terminated-by=...
  2. fields-enclosed-by=...
  3. fields-optionally-enclosed-by=...
  4. fields-escaped-by=...
  5. fields-terminated-by=...

These options are used with-T options and have the same meaning as the load data infile clause.

Load data infile syntax.

-F, flush-logs

Wash the log files on the MySQL database backup server before starting the export.

-F, force,

Even if we get an SQL error while exporting a table, continue.

-H, host = ..

Export data from the MySQL database backup server on the named host. The default host is localhost.

-L, lock-tables.

Lock all tables for start export.

-T, no-create-info

Create table statement)

-D, no-data

No row information is written to the table. If you only want to export the structure of a table, this is very useful!

Opt

Same:

Quick add-drop-table add-locks extended-insert lock-tables

You should be given the fastest possible export to read a MySQL database backup server.

-Pyour_pass, password [= your_pass]

The password used to connect to the server. If you do not specify "= your_pass", mysqldump requires a password from the terminal.

-P port_num, port = port_num

The TCP/IP Port used to connect to a host. (This is used to connect to a host other than localhost because it uses Unix sockets .)

-Q, quick

Directly export the data to stdout without buffering the query; Use MySQL_use_result () to do it.

-S/path/to/socket, socket =/path/to/socket

The socket file used when connecting to localhost (which is the default host.

-T, tab = path-to-some-directory

For each given table, CREATE a table_name. SQL file that contains the SQL CREATE command and a table_name.txt file that contains data. Note: This only works when mysqldump runs on the same machine where the mysqld daemon is running .. The format of the txt file is determined by fields-xxx and linesxxx options.

-U user_name, user = user_name

The username used by MySQL to connect to the server. The default value is your Unix login name.

-O var = option, set-variable var = option

Set the value of a variable. Possible variables are listed below.

 
 
  1. -v, verbose

Lengthy mode. Print out more information about the program.

 
 
  1. -V, version

Print the version information and exit.

 
 
  1. -w, -- where='where-condition'

Only selected records are exported. Note that the quotation marks are mandatory!

 
 
  1. "--where=user='jimf'" "-wuserid>1" "-wuserid1"

The most common use of mysqldump may make a backup of the entire database:

 
 
  1. mysqldump --opt database > backup-file.sql

However, it is also useful for enriching another MySQL database backup with information from one database:

 
 
  1. mysqldump --opt database
  2. MySQL--host=remote-host -C database

Mysqldump exports a complete SQL statement, so it is easy to use the MySQL database to back up the customer program to import the data:

 
 
  1. mysqladmin create target_db_name
  2. MySQL target_db_name backup-file.sql

MySQL database backup is not frequently encountered in general, but it is not a bad thing to be familiar with one more knowledge. When using MySQL database backup, it is intended for people who have just been in contact to protect the database from data loss caused by misoperations.

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.