亚洲步兵一区二区三区_久久精品视频免费多多_玖玖资源站在线免费观看_丝袜制服国产欧美亚洲

長治網(wǎng)站建設(shè)
Mysql 5.6主從同步配置與解決方案

主庫IP:192.168.1.10

從庫IP:192.168.1.11

1、主庫配置編輯my.cnf:

復(fù)制代碼
# 啟用二進(jìn)制日志
log_bin = mysql-bin

server-id = 111 log-bin-index=mysql-bin.index

sync_binlog=1 binlog_format=mixed

binlog-do-db = testdb //同步數(shù)據(jù)庫 binlog-ignore-db = mysql

binlog-ignore-db = performance_schema

binlog-ignore-db = information_schema

binlog_checksum=NONE
復(fù)制代碼

2、創(chuàng)建同步賬號

mysql> grant replication slave on *.* to slave@192.168.1.11 identified by '123456' 

3、主庫狀態(tài)

復(fù)制代碼
mysql> flush privileges;
mysql> show master status; +------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000008 | 337 |              |                  |
+------------------+----------+--------------+------------------+
復(fù)制代碼

記錄下二進(jìn)制日志文件名和位置

4、從庫配置文件配置

 

復(fù)制代碼
# [必須]啟用二進(jìn)制日志
log-bin=mysql-bin   
# [必須]服務(wù)器唯一ID,默認(rèn)是1,一般取IP最后一段
server-id=222 relay-log-index = slave-relay-bin.index

relay-log = slave-relay-bin

sync_master_info = 1 sync_relay_log = 1 sync_relay_log_info = 1
復(fù)制代碼

 

5、配置連接主庫

mysql> change master to master_host='192.168.1.10',master_user='slave',master_password='123456', master_log_file='mysql-bin.000008',master_log_pos=337;

6、開始同步

mysql> start slave;
mysql> show slave statusG;

7、正常狀態(tài)

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

8、解決主從不同步

先上Master庫:

mysql>show processlist;   查看下進(jìn)程是否Sleep太多。發(fā)現(xiàn)很正常。

show master status; 也正常。

mysql> show master status;
+-------------------+----------+--------------+-------------------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB              |
+-------------------+----------+--------------+-------------------------------+
| mysqld-bin.000001 |     3260 |              | mysql,test,information_schema |
+-------------------+----------+--------------+-------------------------------+
1 row in set (0.00 sec)

再到Slave上查看

mysql> show slave statusG                                                

Slave_IO_Running: Yes

Slave_SQL_Running: No

可見是Slave不同步

下面介紹兩種解決方法:

方法一:忽略錯(cuò)誤后,繼續(xù)同步

該方法適用于主從庫數(shù)據(jù)相差不大,或者要求數(shù)據(jù)可以不完全統(tǒng)一的情況,數(shù)據(jù)要求不嚴(yán)格的情況

解決: 

stop slave;

#表示跳過一步錯(cuò)誤,后面的數(shù)字可變

set global sql_slave_skip_counter =1;

start slave;

之后再用mysql> show slave statusG  查看:

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

ok,現(xiàn)在主從同步狀態(tài)正常

方式二:重新做主從,完全同步

該方法適用于主從庫數(shù)據(jù)相差較大,或者要求數(shù)據(jù)完全統(tǒng)一的情況

解決步驟如下:

1.先進(jìn)入主庫,進(jìn)行鎖表,防止數(shù)據(jù)寫入

使用命令:

mysql> flush tables with read lock;

注意:該處是鎖定為只讀狀態(tài),語句不區(qū)分大小寫

2.進(jìn)行數(shù)據(jù)備份 

#把數(shù)據(jù)備份到mysql.bak.sql文件

[root@server01 mysql]#mysqldump -uroot -p -hlocalhost > mysql.bak.sql

這里注意一點(diǎn):數(shù)據(jù)庫備份一定要定期進(jìn)行,確保數(shù)據(jù)萬無一失

3.查看master 狀態(tài)

mysql> show master status;
+-------------------+----------+--------------+-------------------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB              |
+-------------------+----------+--------------+-------------------------------+
| mysqld-bin.000001 |     3260 |              | mysql,test,information_schema |
+-------------------+----------+--------------+-------------------------------+
1 row in set (0.00 sec)

4.把mysql備份文件傳到從庫機(jī)器,進(jìn)行數(shù)據(jù)恢復(fù)

#使用scp命令

[root@server01 mysql]# scp mysql.bak.sql root@192.168.128.11:/tmp/

5.停止從庫的狀態(tài)

mysql> stop slave;

6.然后到從庫執(zhí)行mysql命令,導(dǎo)入數(shù)據(jù)備份

mysql> source /tmp/mysql.bak.sql

7.設(shè)置從庫同步,注意該處的同步點(diǎn),就是主庫show master status信息里的| File| Position兩項(xiàng)

change master to master_host = '192.168.128.10', master_user = 'slave', master_port=3306, master_password='123456', master_log_file = 'mysqld-bin.000001', master_log_pos=3260;

8.重新開啟從同步

mysql> start slave;

9.查看同步狀態(tài)

mysql> show slave statusG  查看:

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

2006-2014 IT0355.com 山西中聯(lián)科創(chuàng)科技有限公司. All Rights Reserved.
電話:0355-3728808 傳真:0355-3728808
ICP備案號:晉ICP備06003721號本站已通過國際W3C認(rèn)證
關(guān)鍵字:中聯(lián)科創(chuàng),長治網(wǎng)站建設(shè),長治網(wǎng)站推廣,長治網(wǎng)絡(luò)工程,長治軟件開發(fā),山西網(wǎng)站建設(shè),山西軟件開發(fā) 長治五金網(wǎng)