MySQL database backup and recovery tools built: MySQLdump.exe and mysql.exe

Backup of the database is key to the protection of the normal operation of the database, the following article is mainly about small coup MySQL database backup, we all know that the use of privileged user MySQL dump backup of the database required is still relatively small, only need permission to select and lock table is sufficient.

Therefore, a user can create a backup of the database, specifically for backing up the database, the database to avoid accidental damage.

MySQLdump is a good tool to back up MySQL databases. It is with respect to the use phpmyadmin and other backup tools more quickly, but also to avoid limited by php.ini, etc., in the windows system can also be combined with regular scheduled tasks to achieve remote backup database.

Before we have to work back up the database preparation work, first create a database user to perform backup operations --root, password: hust. Secondly, we have to determine which database backup, where to put. Then, determine where to put the backup file of the database.

Suppose our task is to back up a server located on 192.168.1.2, name db_test database, and back up files on D: \ bak \ folder. So we can perform backup and recovery operations using the following method:

1. Data Backup

Complete backup of data in the command line, using

MYSQLDUMP command. Through which data can be text command storage form of the document to a specified folder. 

    Description: To operate in a command-line mode

MySQL database, you must set the environment variable to the computer, right-click "My Computer" 

In the shortcut menu, select "Properties"

Command, in the pop-up dialog box, select the "Advanced" tab, and then in the new pop

Dialog box, click " Environment Variables" button, locate and select the user variable PATH variable text box, click "

Edit "by 

New Zealand, added in variable PATH Variable Value text box

"D: \ AppServ \ MySQL \ bin" (MySQL database

Bin folder of the installation path), then click "OK

"Button which you add the folder path to bin according to their MySQL installation

Positions may be noted in the library,

(If you do not want to configure the "Environment Variables", will have to navigate to the directory where the MySQLdump.exe open a command prompt, simply hold down the shift key while you right directory to find the "Open Command Prompt Here")

    note:

If you use the integrated installer to configure the PHP development environment bad, that

It would be unnecessary for the configuration operations because

Integrated installation package has its own configuration. However, if it is installed independently

MySQL, then they must be above configuration,

MySQL can operate in command-line mode

database.

By MYSQLDUMP

Command to back up the entire database, follow these steps:

(1) We can use the built-in windows command prompt (There are several ways to call a command prompt, the most common is to click on the Start menu, select "Run", type cmd command can be started), at the command prompt enter the following operator command:


    MySQLdump -uroot

-phust -h 192.168.1.2 db_test >

D: \ behind \ bakcup.sql 


In this command:


MySQLdump is myqldump the program name; (here I use the Integrated Development Environment D: \ AppServ \ MySQL \ bin directory)


-u is the database user name, followed by the username root;


-p is the password database, followed later the same password, attention is no space between -p and the password;


-h is the address of the database, if not this show is a local backup of the database ;


db_test name of the database to be backed up;

After backup.sql backup files can also be a .txt extension


>

Indicates that the MySQL database backup files to the back, of course, is followed by the address of the backup file, and note the suffix to use absolute file path, file can also be used .txt.


Once this command is executed, MySQLdump backup operation immediately. Remote Backup database seems to be the network's general remote backup will take some time.


If this command is written in a batch file, scheduled backups of data can be achieved through the windows scheduled tasks.


Because there is no gzip compression engine, so you can not back up databases to compress MySQLdump back up the database in the windows, so if you want to back up files and more frequent cleaning expired MySQL database backup files.

(2) back up the database in PHP

It described earlier from the windows of the "Command Prompt" backup database, how to implement it in PHP?

In PHP database backup, mainly through the exec () function to execute system commands

exec () function is the format:

string

exec(string command)

Command parameters for the system command to be executed. Here the command data sub-table is prepared, for example following instructions:

2. Data recovery

(1) using the built-in command prompt windows

I use the MySQL command. The command format is as follows:

mysql -uroot -proot db_database <F:\db_database.sql "

Mysq Shu command which is used, root on behalf of the -u user name, root password on behalf of the -p, db

One

database represents the number of database name (or table), "<" back number "F: \ db_database.txt" is the location of the database backup files are stored.

The following describes the implementation of database recovery procedure:

(1) Select "Start" / "Run" command.

(2) In the dialog box, enter "cmd", click "OK" button, enter the command line mode.

(3) input in command mode "MySQL -uroot- -proot  db_database <F.: \ Db_database.txt", and "Enter"

(2) to restore the database in PHP











Is known from notes (Wiz)


Guess you like

Origin www.cnblogs.com/mynale/p/11018743.html