|
Mysqldump is mysql tools used for logical backup. In the process of database backup, you need to include a backup, the database itself, data, binary files (used for database even point reduction).
Following is a brief introduction to the next.
Backup starts:
1: landing mysql process, will need to enter a password, enter the password each time if you want to avoid tedious, you can create .my.cnf hidden files in the login user's home directory to root user as an example
vi /root/.my.cnf
[Client]
user = 'root'
password = 'exit'
host = 'localhost'
Again until landing time, landing mysql can directly enter the system.
2: Back up the database
mysql database connection
show master status; // that is used to view the current binary log file.
mysqldump -all-databases -lock-all-tables -flush-logs-master-data = 2> / root`date +% F-% H-% M-% S`.sql
Now the database backup, backup binary log file below, after the backup or data binary log files have been refreshed, says a new binary log file is generated, the file name is the serial number on a binary file plus one.
Binary log files will be backed up before the first flush
mysqlbinlog /data/mydata/mysql-bin.000005> /root/1.sql
mysql database connections increment
use stu;
insert into score (name, score) values ( 'xiaozhang', 96);
select * from score;
quit
One day after the last incremental backup
mysqlbinlog /data/mydata/mysql-bin.000006>/root/2.sql
3: Analog database damage.
cd / data / mydata
rm -rf *
killall mysqld // forced to close off all the processes mysql.
Re-initialize the database
cd / usr / local / mysql
scripts / mysql_install-db --user = mysql -datadir = / data / mydata
Before it restores the database to connect to mysql, the binary log file function off.
mysql
set sql_log_bin = 0 // Binary logging does not need to open the database restore process.
quit
mysql < / root / `date +% F-% H-% M-% S`.sql // just backed up the database.
mysql < /root/1.sql // import binary log files
mysql < /root/2.sql // import binary incremental backup files
The reduction is complete, the connection open mysql binary log function.
mysql
set sql_log_bin = 1
purge binary logs to 'mysql-bin.000006'; // delete No binary log file.
Well, mysqldump logic also previously said that. After continued. |
|
|
|