MYSQL Database Backup

Source: Internet
Author: User
Tags sql error

Using MYSQL for database backup has a very regular database backup method, which has the same concept as other database servers, but have you ever thought about it, mySQL will have a simpler backup method using the file directory, and it will be faster and better.

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 TestA in the hostA host and restore it to the hostB host

Test environment: Chinaz ^ com

Operating System: WinNT4.0, MySQL3.22.34, PHPMyAdmin 2.1.0 medium. Country. Site. Long. Site

Install MySQL database in hostA and create TestA Database

The MySQL database is installed on the hostB machine, and there is no TestA Database

Procedure:

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

 

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

 

In my test environment, this directory is

 

C: MySQLdata

 

Find the subdirectory of the corresponding database name

 

C: MySQLdataTestA

 

Paste the file to the Data directory of HostB.

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. [Chinese webmaster site]

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. China National site long site

Ii. Formal method (officially recommended): Chinaz @ com

MySQL MySQLdump is used for export. The basic usage is as follows:

 

MySQLdump [OPTIONS] database [tables] Chinaz.com

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

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. Chinaz.com

MySQLdump supports the following options:

 

-- Add-locks Chinaz @ com

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

-- Add-drop-table

Add a drop table before each create statement. Www_Chinaz_com

-- Allow-keywords

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

-C, -- complete-insert China. Station. Long SITE

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

-- 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] Chinaz

Tracking Program usage (for debugging ). Www ~ Chinaz ~ Com

-- Help

 

Displays a help message and exits.

-- Fields-terminated-by =...

 

-- Fields-enclosed-by =... Chinese site

-- Fields-optionally-enclosed-by =...

-- Fields-escaped-by =...

 

-- 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 site. Long SITE

Wash Out the log files on the MySQL server before starting the export. Station. Long SITE

-F, -- force, Chinese site. Long SITE

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

 

-H, -- host = ..

 

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

 

 

-L, -- lock-tables.

 

Lock all tables for start export.

-T, -- no-create-info Station. Long SITE

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! Chinaz @ com

-- Opt

Same as -- quick -- add-drop-table -- add-locks -- extended-insert -- lock-tables.

 

You should be given the fastest export possible for reading a MySQL server.

-Pyour_pass, -- password [= your_pass] Chinese Webmaster. Station

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 China. webmaster site

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 Chinese webmaster.

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 the options -- fields-xxx and -- lines -- xxx.

 

-U user_name, -- user = user_name

 

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

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

 

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

-V, -- verbose Chinese site. Long. Station

Lengthy mode. Print out more information about the program. China webmaster site

-V, -- version

 

Print the version information and exit.

 

-W, -- where = 'where-condition'

 

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

 

"-- Where = user = 'jimf '"-wuserid> 1 ""-wuserid <1 "Www_Chinaz_com

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

MySQLdump -- opt database> backup-file. SQL

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

 

Mysqldump -- opt database | MySQL -- host = remote-host-C database

Mysqldump exports complete SQL statements, so it is easy to import data into MySQL client programs:

 

MySQLadmin create target_db_name Chinese site. Long SITE

MySQL target_db_name <backup-file. SQL

Related Article

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.