參考文檔:http://www.178linux.com/60625
創(chuàng)新互聯(lián)網(wǎng)站建設(shè)服務(wù)商,為中小企業(yè)提供做網(wǎng)站、網(wǎng)站制作服務(wù),網(wǎng)站設(shè)計(jì),網(wǎng)站托管維護(hù)等一站式綜合服務(wù)型公司,專業(yè)打造企業(yè)形象網(wǎng)站,讓您在眾多競(jìng)爭(zhēng)對(duì)手中脫穎而出創(chuàng)新互聯(lián)。
節(jié)點(diǎn)一
修改配置文件設(shè)置唯一ID開(kāi)起二進(jìn)制日志
[root@node1 ~]# vim /etc/my.cnf 增加以下內(nèi)容 [MySQLd] log-bin=master_bin 開(kāi)起二進(jìn)制日志 server_id=1 給主節(jié)點(diǎn)一個(gè)唯一的ID號(hào) innodb_file_per_table=on innodb開(kāi)起獨(dú)立表空間 skip_name_resolve=on 開(kāi)啟跳過(guò)主機(jī)名反解
啟動(dòng)服務(wù)創(chuàng)建有遠(yuǎn)程復(fù)制權(quán)限的賬戶
[root@node1 ~]# service mariadb start [root@node1 ~]# mysql MariaDB [(none)]> show global variables like '%log%'; 查看二進(jìn)制日志log_bin是否開(kāi)啟了 MariaDB [(none)]> show global variables like '%server%'; 查看DI號(hào)是否為1 MariaDB [(none)]> show master logs; 查看主節(jié)點(diǎn)二進(jìn)制日志的位置,從節(jié)點(diǎn)從主節(jié)點(diǎn)最后一個(gè)日志的位置開(kāi)始復(fù)制 MariaDB [(none)]> grant replication slave,replication client on *.* to 'copy'@'192.168.%.%' identified by 'passwd'; 創(chuàng)建并授權(quán)一個(gè)遠(yuǎn)程復(fù)制賬號(hào)copy密碼為passwd MariaDB [(none)]> flush privileges; 刷新用戶權(quán)限
修改配置文件設(shè)置唯一ID開(kāi)起中繼日志
[root@node2 ~]# vim /etc/my.cnf relay_log=relay_log 開(kāi)起中繼日志 relay-log-index=relay-log.index server_id=2 同樣的也需要設(shè)置唯一的ID號(hào) innodb_file_per_table=on skip_name_resolve=on [root@node2 ~]# service mariadb start [root@node2 ~]# mysql MariaDB [(none)]> show global variables like '%log%'; 查看中繼日志relay_log是否開(kāi)起 MariaDB [(none)]> show global variables like '%server%'; 查看ID號(hào)是否為2 主節(jié)點(diǎn)為192.168.1.107,遠(yuǎn)程復(fù)制賬號(hào)為copy,密碼為passwd,復(fù)制二進(jìn)制日志的起始位置為000003的245處 MariaDB [(none)]> change master to master_host='192.168.1.107',master_user='copy',master_password='passwd',master_log_file='master_bin.000003',master_log_pos=245; MariaDB [(none)]> start slave; 啟動(dòng)從節(jié)點(diǎn)復(fù)制線程 MariaDB [(none)]> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.107 Master_User: copy Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master_bin.000003 Read_Master_Log_Pos: 491 Relay_Log_File: relay_log.000003 Relay_Log_Pos: 776 Relay_Master_Log_File: master_bin.000003 Slave_IO_Running: Yes 這兩項(xiàng)必須為yes Slave_SQL_Running: Yes 這兩項(xiàng)必須為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: 491 Relay_Log_Space: 1064 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: 1 1 row in set (0.00 sec)
如果Slave_IO_Running
不為yes的解決辦法
如:ERROR 1201 (HY000)
MariaDB [(none)]> slave stop; 停止從節(jié)點(diǎn) MariaDB [(none)]> reset slave; 重新設(shè)置從節(jié)點(diǎn)
查找設(shè)置有問(wèn)題的地方重新給從節(jié)點(diǎn)授權(quán)
MariaDB [(none)]> change master to master_host='192.168.1.107',master_user='copy',master_password='passwd',master_log_file='master_bin.000003',master_log_pos=245; MariaDB [(none)]> start slave; 啟動(dòng)從節(jié)點(diǎn) MariaDB [(none)]> show slave status\G; 查看狀態(tài)
注意從節(jié)點(diǎn)上一定不能進(jìn)行寫操作
主節(jié)點(diǎn)
MariaDB [(none)]> create database msdb; MariaDB [msdb]> create table xx (id int(4) not null auto_increment,name varchar(30) not null,primary key(id)) engine=innodb charset=utf8; MariaDB [msdb]> insert into xx (id,name) values (1,'king');
從節(jié)點(diǎn)
MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | msdb | | mysql | | performance_schema | | test | +--------------------+ MariaDB [(none)]> use msdb; MariaDB [msdb]> show tables; +----------------+ | Tables_in_msdb | +----------------+ | xx | +----------------+ MariaDB [msdb]> select * from xx; +----+------+ | id | name | +----+------+ | 1 | king | +----+------+
文章名稱:Mysql之主從復(fù)制
本文地址:http://www.chinadenli.net/article30/jcocpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、外貿(mào)建站、微信小程序、虛擬主機(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)