提示:
1.主IO线程,从IO,SQL线程来完成
2.如果从库还想级联,需要打开log-bin和log-slave-updates参数
配置流程: 1.打开logbin 2.创建专用同步帐号 3.锁表,然后查看pos备份点,并记录。(或者备份时请加参数:--master-data=1 或2,锁表加 -x) 4.开始备份,解锁,(建议再确定表是否锁住) 5.从库开始恢复备份 6.从库配置连接主库 7.启动,检查线程是否工作
#Mster主库----打开logbin vim my.cnf log-bin = /data/3306/mysql-bin server-id = 1 -------------------------------------------------------------------------------------------------- #创建专用同步帐号 grant replication slave on *.* to 'rep'@'192.168.1.%' identified by '123456'; //创建 flush privileges; //刷新权限 flush table with read lock; //锁表,禁止再写入数据 MySQL5.1: flush tables with read lock; mysql> show master status; //查看pos备份点 +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000008 | 12409 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec) -------------------------------------------------------------------------------------------------- #开始备份 mysqldump -uroot -p'123456' -S /data/3306/mysql.sock -A -B --events|gzip >/opt/rep.sql.gz show master status; //建议再确定表是否锁住 unlock tables; //解开表锁 加--master-data=2 -x 参数 mysqldump -uroot -p'123456' -S /data/3306/mysql.sock -A -B --events --master-data=2 -x |gzip >/opt/rep.sql.gz --------------------------------------------------------------------------------------------------
#slave 从库 mysql -uroot -p'123456' -S /data/3307/mysql.sock</opt/rep.sql //恢复备份 #从库配置连接主库 [root@A-host ~]# mysql -uroot -p'123456' -S /data/3307/mysql.sock change master to master_host='192.168.1.10', master_port=3306, master_user='rep', master_password='123456', master_log_file='mysql-bin.000008', //备份时如果指定了--master-data=1 ,此条不用写 master_log_pos=12409; //备份时如果指定了--master-data=1 ,此条也不用写 #启动 start slave; show slave status\G 表示正常: Slave_IO_Running: Yes Slave_SQL_Running: Yes
#知识扩展 主库线程同步状态: show processlist\G 从库查看状态: show slave status\G 让mysql slave记录binlog的方法 log-slave-updates log-bin=mysql3306-bin expire_logs_days =7
MySQL主从复制(M-M) #Master1 [mysqld] auto_increment_increment = 2 #自增ID的间隔,如1 3 5 间隔为2 auto_increment_offset = 1 #ID的初始位置 #Master2 [mysqld] auto_increment_increment = 2 #自增ID的间隔,如2 4 6 间隔为2 auto_increment_offset = 2 #ID的初始位置
停留在世界边缘,与之惜别