windows mysql主 Linux mysql 從 主從同步,讀寫分離

Mysql –master linux-slavemysql

 

1、My.ini:linux

Server-id=1sql

relay-log=relay-bin數據庫

relay-log-index=relay-bin-index服務器

binlog-do-db = studyyiiyii

 

重啓服務器ide

登錄mysqlspa

Mysql –u root –prest

在主數據庫創建slave鏈接的權限:code

mysql> grant replication slave,reload,super on *.* to 'root'@'172.31.80.31' iden

tified by 'root';

(root爲鏈接的帳號,IP 和密碼)

Show master status;

 

記住,之前我沒設置權限,顯示的position爲120 一直由於沒開權限麼啓動

至此,Windows mysql master 設置完畢

 

2、打開Linux mysql

 Vi /etc/my.cnf #根據你服務器MySQL的設置來編輯,編輯mysql的配置文件

在MySQLd下面添加配置:

 

 

server_id = 2 #從服務器標識,範圍1---2E32-1
log_bin = mysql_bin
binlog_do_db = studyyii
binlog_ignore_db = mysql

replicate-ignore_db = mysql #不一樣步的數據庫名稱,多個能夠重複該配置

:wq 保存退出

 

Service mysql restart  #個人mysql是5.6.23 已經添加爲系統服務,其它一下版本是mysqld ,反正就是重啓mysql,根據本身的配置來

 

Mysql –u root –p #鏈接mysql

設置鏈接master:

mysql->change master to master_host='172.31.80.26',master_user='root',master_password='root', master_log_file='mysql-bin.000014',master_log_pos=344;

 

#鏈接的帳戶 IP 密碼爲mastermysql的。Master_log_file 和log_pos 爲前期Windows mysql的show master status 中看到。

 

出現OK以後

Start slave;啓動slave

查看狀態

Show slave status\G;

 

 Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.31.80.26
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000014
          Read_Master_Log_Pos: 344
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000014
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql

 

當slave_IO_Running 和Slave_SQL_Running 都爲yes  說明配置成功。

若是IO_Running 爲connecting 說明一直在鏈接,你的配置是有問題的,

檢查master 是否有錯誤,檢查slave鏈接master是否有問題,

 

而後你就看到更改數據 數據庫能夠同步了。

 

注: 若是添加多個從數據庫,配置my.cnf id要更換一下,另外就是master要記得加上權限,

mysql> grant replication slave,reload,super on *.* to 'root'@'172.31.80.31' iden

tified by 'root';

相關文章
相關標籤/搜索