這篇文章主要講解了“Linux環(huán)境下MySQL5.6 Master-Slave的搭建步驟”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Linux環(huán)境下MySQL5.6 Master-Slave的搭建步驟”吧!
創(chuàng)新互聯(lián)建站長(zhǎng)期為上1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為永順企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè),永順網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
Master-Slave搭建步驟:
1、在兩臺(tái)主機(jī)分別安裝MySQL數(shù)據(jù)庫(kù)軟件
2、在兩臺(tái)主機(jī)分別創(chuàng)建并初始化MySQL數(shù)據(jù)庫(kù)實(shí)例
3、從主庫(kù)dump數(shù)據(jù)(庫(kù))導(dǎo)入到備庫(kù)
4、修改主從(Master-Slave)配置
5、主庫(kù)grant、從庫(kù)啟動(dòng)復(fù)制(start slave)
6、驗(yàn)證主備數(shù)據(jù)同步
--master:
grant replication slave,replication client on *.* to 'slave'@'192.168.100.81' identified by 'slave';
導(dǎo)出:
flush tables with read lock;
mysql> insert into tony(tid,tdept) values (20001,'ty');
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock
mysqldump -uroot -p -E -R -A --databases tyms> /mysql/data/tyms_master.sql
slave導(dǎo)入:
mysql命令行
mysql>source /mysql/data/tyms_master.sql;
--master:
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
---slave:
change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
(root@localhost) [(none)]> change master to master_host='192.168.100.71', master_user='slave', master_password='slave', master_log_file='mysql-bin.000014', master_log_pos=594;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
--master:
unlock tables;
---slave:
mysql> start slave;
[tyms]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.71
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 3051261
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 3050950
Relay_Master_Log_File: mysql-bin.000014
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 3051261
Relay_Log_Space: 3051123
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1000
Master_UUID: 845f69fa-c558-11e5-9462-000c297b003d
Master_Info_File: /mysql/data/mysqldata/mydata/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
[tyms]> show binlog events in '/mysql/data/mysqldata/mydata/mysql-bin.000014' from 3051261;
[(none)]> select version();
+------------+
| version() |
+------------+
| 5.6.28-log |
+------------+
1 row in set (0.00 sec)
可以看到:Slave_IO_Running | Slave_SQL_Running兩個(gè)值都是YES,說(shuō)明配置成功了??梢栽谥鲙?kù)里執(zhí)行DML或者DDL驗(yàn)證下。
如果同步不成功:
1:停掉從庫(kù)
mysql> slave stop
2:主庫(kù)上找到日志和位置
mysql> show master status;
(root@localhost) [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000014 | 594 | | | |
+------------------+----------+--------------+------------------+-------------------+
3:手動(dòng)同步
mysql> change master to
> master_host='master_ip',
> master_user='gechong',
> master_password='gechong',
> master_port=3306,
> master_log_file='mysql-bin.000014',
> master_log_pos=594;
1 row in set (0.00 sec)
4:?jiǎn)?dòng)從庫(kù)
mysql> slave start;
1 row in set (0.00 sec)
如果有異常需要可執(zhí)行跳過(guò):
>slave stop;
>SET GLOBAL sql_slave_skip_counter = 1;
>slave start;
Created by Tony.Tang[TangYun]2016.02
----------------------End--------------------------
感謝各位的閱讀,以上就是“Linux環(huán)境下MySQL5.6 Master-Slave的搭建步驟”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Linux環(huán)境下MySQL5.6 Master-Slave的搭建步驟這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
當(dāng)前標(biāo)題:Linux環(huán)境下MySQL5.6Master-Slave的搭建步驟
本文URL:http://www.rwnh.cn/article30/peoppo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站維護(hù)、Google、App設(shè)計(jì)、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)