A method of MySQL backup database

Source: Internet
Author: User
Tags mysql backup mysql backup database

Today added a database automatic backup module, MySQL data backup method has many, can be a single database backup, can be multiple database backup, or a table can be backed up, you can only back up the database
The structure does not back up the data, can do different processing according to need, just now a bit of time, simple record the simplest kind of backup method.

MySQL Version: 5.1

1. Use mysqldump to back up the MySQL database
Mysqldump is a separate executable program, not a command for the MySQL runtime, and when using mysqldump, if it is under Windows, you need to add the environment variable to the system path before you can perform the backup operation from the command line
See how to use mysqldump:
Command Line input command mysqldump--help
To back up a database:
mysqldump-hhost-uusername-ppswd databasename > Path//backupfile.sql
-h Specifies the hostname, the host name above, if it is native, can be designated as localhost, if it is Telnet, with the destination host IP address can be
-u Specifies user name, above username indicates user name
-p Specifies the user's login password, above PSWD indicates the user username login password
DatabaseName indicates the name of the database to be backed up
Symbol > is a redirect symbol that you can use to specify the files and paths to dump
Path is a route, such as F://databasebackup
Backupfile.sql the file name after the dump, the backed up data is implemented in MySQL script, which contains SQL statements to create tables and data

For example: the current database to be backed up is TestDB, backup it to the Testdb.sql file under the F-packing directory, assuming the root user's password is 888888
At the command line, enter:
mysqldump-hlocalhost-uroot-p888888 TestDB > F:/testdb.sql

2. Use the file you just backed up to restore the database using the source command
There are 2 conditions when restoring a database with the source command:
1) successfully login to MySQL above.
2) The database must exist, but cannot have the corresponding table and data, just an empty name, because the use of the above method to back up the MySQL script, which is to create tables and insert data SQL statements, the use of backup files to restore
is actually executing a series of SQL statements.

For example, to restore the above database TestDB
Command line enter the following command
1) log in to MySQL
mysql-hlocalhost-uroot-p888888
2) Delete the original database
Drop Database TestDB
3) Create the database to be recovered
Create DATABASE TestDB2
4) Select Database
Use testDB2
5) Create tables and import data from using the source command and SQL scripts
SOURCE F:/testdb.sql

TIP: Sometimes you forget the parameter information about the command, just remember the help options and commands to see your own helpful information

For example: Mysqldump--help will show a lot of usage descriptions of mysqldump, and then you can do it as needed
After logging on to MySQL, you can also use the Help command to view information about an SQL statement, for example: the Select
Syntax information of the statement, it is really convenient!

A method of MySQL backup database

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.