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