Command to back up and restore a mysql database

Source: Internet
Author: User
There are various methods to back up and restore the database in mysql, but they are all executed based on the mysql mysqldump command. Whether you are using phpmyadmin or command, I will introduce it to you below.

There are various methods to back up and restore the database in mysql, but they are all executed based on the mysql mysqldump command. Whether you are using phpmyadmin or command, I will introduce it to you below.

Restore one: mysql-h localhost-u root-p123456 www

Back up one:-h localhost-u root-p123456 www> d:/www2008-2-26. SQL


Backup Data:

The Code is as follows:

Mysqldump-u user name-p Password Database Name> XX. SQL

Example

Start Menu | run | cmd | use the "cd/Program Files/MySQL Server 5.0/bin" command to enter the bin folder | use "mysqldump-u username-p databasename> exportfilename" to export database to file, for example, mysqldump-u root-p voice> voice. SQL, and then enter the password to start exporting

You can use gzip to compress large data volumes.

The Code is as follows:

Mysqldump-u user name-p Password Database Name | gzip> XX. SQL .gz

Recover data:

The Code is as follows:

Mysql-u username-p Password Database Name <XX. SQL

Example

Enter the MySQL Command Line Client, enter the password, go to "mysql>", enter the Command "show databases;", Press enter to see what databases are there, and create the database you want to restore, enter "create database voice;", Press ENTER; switch to the database you just created, enter "use voice;", Press ENTER; import data, and enter "source voice. SQL; ", Press enter to start importing, and" mysql> "is displayed again. If no error is returned, the restoration is successful.


Direct Recovery from gzip compressed files

The Code is as follows:

Gzip <XX. SQL .gz | mysql-u username-p Password Database Name

Example

Back up data using the mysqldump command:
In the Command Prompt window (note that it is not the MySQL Command Line Client window of MySQL), enter,

The Code is as follows:

Mysqldump-hlocalhost-uroot-proot temp> temp_2011. SQL
Mysqldump-hlocalhost-u root-proot temp> temp_2011. SQL
Mysqldump-h localhost-u root-proot temp> temp_2011. SQL

First, go to the directory where MySQL wants to store the backup file (which is easy to store the generated *. SQL file ).

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.