PHP performs backup and restore of MySQL database

Source: Internet
Author: User

Using the mysqldump command to back up

The mysqldump command backs up the data in the database into a text file. The structure of the table and the data in the table are stored in the generated text file.

The mysqldump command works very simply. It first identifies the structure of the table that needs to be backed up, and then generates a CREATE statement in the text file. Then, convert all the records in the table into an INSERT statement. With these statements, you can create tables and insert data.

Mysqldump Basic Syntax:

Mysqldump-u username-p Password dbname table1 table2 ...-> backupname.sql

Username is the database user name;

Password for database password

The dbname parameter represents the name of the database;
The table1 and table2 parameters represent the names of the tables that need to be backed up, and the entire database is backed up as empty;
Backupname.sql parameter table design the name of the backup file with an absolute path before the file name. Typically the database is partitioned into a file with a suffix called SQL;

$exec= "D:/phpstudy/mysql/bin/mysqldump-u". $db _user. " -P ". $db _pwd. "". $db _name. " > ". $name ; exec ($exec); // the path to the MySQL execution file is set up earlier. 

Note: There is no space in the password after-p, otherwise it will only generate an empty SQL file, followed by $name is the path and name of the generated file.

The simple backup database is complete.

1. Restore the syntax of a database backed up using the mysqldump command

Mysql-u root-p Password dbname < backup.sql

parameter is the same as the backup, Backup.sql is the database file that needs to be restored, the file path is absolute path.

PHP performs backup and restore of MySQL database

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.