mysql熱備份主要分為主從備份和主主備份兩種,下面介紹mysql實現主從備份的方法
1.主服務器配置
[mysqld]
#主從備份
log-bin=mysql-bin
binlog_format=mixed
server-id=1
read-only=0
binlog-do-db=mydb
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
#雙主備份
#auto-increment-increment=10
#auto-increment-offset=1
2.從服務器配置
[mysqld]
#主從備份
#log-bin=mysql-bin
#binlog_format=mixed
server-id=2
replicate-do-db=mydb
replicate-ignore-db=mysql
replicate-ignore-db=test
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-wild-ignore-table=mydb.000%
replicate-wild-ignore-table=mydb.tmp%
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%
relay_log=mysql-relay-bin
log-slave-updates=ON
3.在mysql中創建一個備份用戶
grant replication slave on *.* to 'backup'@'192.168.0.42' identified by '123456';
4.在從服務器中開啟主從備份
mysql> CHANGE MASTER TO
MASTER_HOST='192.168.0.41',
MASTER_USER='backup',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=106;
5.主從備份開啟后,重啟mysql服務即可
sudo service mysql restart