mysql的主从项目经验_mysql5.5主从经验分享
[email?protected] ~]# mysql -uroot –p123456
mysql> GRANT REPLICATION SLAVE ON . TO ‘root‘@‘slave_IP‘ IDENTIFIED BY ‘123456‘;
第四部:主數(shù)據(jù)庫鎖表(禁止再插入數(shù)據(jù)以獲取主數(shù)據(jù)庫的的二進(jìn)制日志坐標(biāo))
mysql> flush tables with read lock;(這一步看自己實(shí)際情況,有些必須有些不是必須的)
第五步:查看主數(shù)據(jù)庫的狀態(tài)(并記錄下File字段和Position字段的值,在配置從服務(wù)器時(shí)有用到)
第六步:導(dǎo)出master數(shù)據(jù)庫。
#mysqldump -uroot -p123456 --all-databases --triggers --routines --events >
/home/alldatabases.sql
第七步:解鎖master數(shù)據(jù)庫鎖表操作
mysql -uroot -p (本命令在主數(shù)據(jù)庫服務(wù)器上執(zhí)行)
mysql> unlock tables;
第八步:把master到處的數(shù)據(jù)庫同步到slave數(shù)據(jù)庫上;
第九步:在slave數(shù)據(jù)庫上導(dǎo)入master的數(shù)據(jù)庫
mysql -uroot –p123456 < /home/alldatabases.sql
第十步:在從數(shù)據(jù)庫服務(wù)器上設(shè)置主數(shù)據(jù)庫服務(wù)器向從數(shù)據(jù)庫服務(wù)器同步
mysql -uroot –p123456
mysql> change master to master_host = ‘172.16.244.31‘,master_user=‘root‘,master_password=‘123456‘,master_log_file=‘master-bin.000015’,master_log_pos=120;
第十一步:啟動(dòng)從數(shù)據(jù)庫復(fù)制線程
mysql> start slave;
第十二步:查詢從數(shù)據(jù)庫的復(fù)制線程狀態(tài)
mysql> show slave status \G
如果 Slave_IO_Running: Yes
Slave_SQL_Running: Yes
此兩項(xiàng)為yes則主備成功;如果不成功重新操作;但在第十步操作如下:
mysql -uroot –p123456
mysql>stop slave;
mysql>reset slave;
mysql> change master to master_host = ‘172.16.244.31‘,master_user=‘repl‘,master_password=‘123456‘,master_log_file=‘’master-bin.000011‘,master_log_pos=330;
如果之前做過主從備份,記得master上執(zhí)行 mysql>reset master; 從數(shù)據(jù)庫操作 stop slave; reset slave;
change master to master_host = ‘172.16.244.31‘,master_user=‘root‘,master_password=‘123456‘,master_log_file=‘master-bin.000169‘,master_log_pos=57496820;
方法二:
mysqldump -u root -p123456 --single-transaction --events --triggers --routines --flush-logs --master-data=2 --all-databases > xx.sql這是導(dǎo)所有數(shù)據(jù)庫
grep -i "change master" xx.sql通過這個(gè)取出sql中的同步點(diǎn)。導(dǎo)入后就可以用這個(gè)信息重新做同步點(diǎn)
原文:http://blog.51cto.com/xiaobailiunx/2085503
總結(jié)
以上是生活随笔為你收集整理的mysql的主从项目经验_mysql5.5主从经验分享的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 多表联查的效率_Mysql
- 下一篇: python模块xlwt怎么用不了_py