MySQL database backup and restore

Source: Internet
Author: User

Database backup:

Open cmd to execute the following statement:

The code is as follows Copy Code

Mysqldump-h localhost-u root-proot databasename >d:databasename.sql

Database restore:

Open cmd to execute the following statement

The code is as follows Copy Code

Mysql-uroot-proot DatabaseName < D:databasename.sql

When database backup and restore operations are not on the same database server, there may be coding problems with MySQL software installation for two servers

For example, when you restore a database, you will encounter the "Unknown command". "This error hint

You can use the

The code is as follows Copy Code

Mysql-uroot-proot--default-character-set=gb2312 DatabaseName < D:databasename.sql


Mysqlhotcopy

2.1 Backup
Mysqlhotcopy is a PERL program that was originally written by Tim Bunce. It uses LOCK tables, FLUSH tables, and CP or SCP to quickly back up databases. It is the quickest way to back up a database or a single table, but it can only run on the same machine as the database file (including the datasheet definition file, the data file, the index file). Mysqlhotcopy can only be used for backup MyISAM and can only be run on Unix-like and NetWare systems.

Mysqlhotcopy supports the one-time copying of multiple databases while also supporting regular expressions. Here are a few examples:

The code is as follows Copy Code

Root#/usr/local/mysql/bin/mysqlhotcopy-h=localhost-u=yejr-p=yejr db_name/tmp (Copy the database directory db_name to/tmp)

Root#/usr/local/mysql/bin/mysqlhotcopy-h=localhost-u=yejr-p=yejr db_name_1 ... db_name_n/tmp
ROOT#/USR/LOCAL/MYSQL/BIN/MYSQLHOTCOPY-H=LOCALHOST-U=YEJR-P=YEJR db_name./regex//tmp

For more detailed instructions, check the manual, or call the following command to view Mysqlhotcopy's help:

The code is as follows Copy Code

Perldoc/usr/local/mysql/bin/mysqlhotcopy

Note that to use mysqlhotcopy, you must have SELECT, RELOAD (to perform FLUSH TABLES) permissions, and you must also have permission to read the Datadir/db_name directory.


2.2 Restore

Mysqlhotcopy Backup is the entire database directory, use can be directly copied to the mysqld specified DataDir (here is/usr/local/mysql/data/) directory, but also attention to the issue of permissions, the following example:

The code is as follows Copy Code
ROOT#CP-RF db_name/usr/local/mysql/data/
Root#chown-r nobody:nobody/usr/local/mysql/data/

(Change the owner of the Db_name directory to mysqld run user)

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.