标签:
1、 设置Master服务器
server-id=1
log-bin=/var/lib/mysql/mysql-bin
//为了使用事务的InnoDB在复制中最大的持久性和一致性,你应该指定innodb_flush_log_at_trx_commit=1,sync_binlog=1选项
innodb_flush_log_at_trx_commit=1
sync_binlog=1
2、 设置Slave服务器
Binlog_format=mixed
Max_allowed_packet=12M
Lower_case_table_names=1
Server-id = 8
Report-host=xxx.xxx.xxx.xxx
Report-user=replslave
Report-password=XXX
Log-bin=slave-bin.log
3、 用户信息同步
由于用户在创建视图等时候,会记录下创建视图的用户名密码。所以需要创建相同的用户名及主机地址
a) 锁定Master服务器
flush tables with read lock;
b) 查询Binlog状态
show master status;
c) 导出Master数据
mysqldump --default-character-set=utf8mb4 --opt -u admin --password=ILoveQihuohui! -h Master地址 备份数据库 > bak.sql
重新打开主机Master写操作功能
unlock tables;
d) 导入Master数据到Slave服务器
mysql -uroot -p --default-character-set=utf8mb4 dbname < bak.sql
e) 设置Slave服务器
stop slave;
mysql>change master to master_host=‘192.168.1.2‘,
->master_user=‘repl_user‘,
->master_password=‘123456‘,
->master_log_file=‘mysql-bin.000013‘,
->master_log_pos=7863951;
start slave;
a) 查询Binlog状态
show master status;
b) 导出Master数据
mysqldump --default-character-set=utf8mb4 --opt -u admin --password=ILoveQihuohui! -h Master地址 备份数据库 > bak.sql
c) 导入Master数据到Slave服务器
mysql -uroot -p --default-character-set=utf8mb4 dbname < bak.sql
d) 确认Binlog具体位置
需要找到附近位置,并定位到具体的sql语句
Show Binlog Events In ‘mysql-bin.000013‘ from 7863951
e) 设置Slave服务器
stop slave;
mysql>change master to master_host=‘192.168.1.2‘,
->master_user=‘repl_user‘,
->master_password=‘123456‘,
->master_log_file=‘mysql-bin.000013‘,
->master_log_pos=7863951;
start slave;
自动备份脚本:
需要创建一个自读用户,该用户需要有备份的数据库以下权限:
select、Lock Tables、Show View
脚本如下:
@echo off
set h=%time:~0,2%
set h=%h: =0%
set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%%h%"
md g:\db_backups\%Ymd%
"D:\xampp\mysql\bin\mysqldump" --default-character-set=utf8mb4 --opt -u dev --password=winbei888 -h 10.100.1.76 winbei_production > g:\db_backups\%Ymd%\winbeidb.sql
"D:\xampp\mysql\bin\mysqldump" --default-character-set=utf8mb4 --opt -u dev --password=winbei888 -h 10.100.1.76 openfire > g:\db_backups\%Ymd%\openfiredb.sql
g:\db_backups\7za.exe a -r g:\db_backups\backdata\%Ymd%.zip g:\db_backups\%Ymd%\*
rd g:\db_backups\%Ymd%\ /S/Q
@echo on
标签:
原文地址:http://www.cnblogs.com/huangxianggui/p/4825385.html