天天看點

Mysql主從資料庫配置環境介紹配置

這裡寫自定義目錄标題人

  • 環境介紹
  • 配置

環境介紹

mysql主從配置。本人是在如下環境測試的:

主資料庫所在的作業系統:windows server2008

主資料庫的版本:5.5

主資料庫的ip位址:192.168.0.141

從資料庫所在的作業系統:ubuntu

從資料的版本:5.5

從資料庫的ip位址:192.168.0.126

配置

1.在主庫上設定同步賬号

GRANT REPLICATION SLAVE,FILE ON . TO ‘mstest’@‘192.168.0.126’ IDENTIFIED BY ‘123456’;

注:  192.168.0.126:是從庫的ip位址
	 		mstest:是新建立的使用者名    	
	 		123456:是新建立的使用者名的密碼
           

2.配置主資料庫的my.ini

[mysqld]

server-id=1

log-bin=log

binlog-do-db=mstest //要同步的mstest資料庫,要同步多個資料庫,就多加幾個replicate-db-db=資料庫名

binlog-ignore-db=mysql //要忽略的資料庫

3.重新開機主資料庫

4.驗證主庫是否成功

show slave status;

Mysql主從資料庫配置環境介紹配置

5.配置從資料庫的my.cnf

[mysqld]

server-id=2

master-host=192.168.1.111

master-user=mstest   //第一步建立賬号的使用者名

master-password=123456 //第一步建立賬号的密碼

master-port=3306

master-connect-retry=60

replicate-do-db=mstest //要同步的mstest資料庫,要同步多個資料庫,就多加幾個replicate-db-db=資料庫名

replicate-ignore-db=mysql  //要忽略的資料庫

6.重新開機從資料庫

/etc/init.d/mysql restart

7.驗證是否成功

show slave status;

Mysql主從資料庫配置環境介紹配置

遇到的坑:

一、出現Slave_SQL_Running:no和slave_io_running:no問題的解決方法

1.如果是Slave_SQL_Running:no:

MariaDB [(none)]> stop slave;

MariaDB [(none)]> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

MariaDB [(none)]> start slave;

2.如果是slave_io_running:no

MariaDB [(none)]> slave stop;

MariaDB [(none)]>CHANGE MASTER TO MASTER_LOG_FILE=‘log.000003’;

MariaDB [(none)]> slave start;

二、start slave時報錯The server is not configured as slave; fix in config file or with CHANGE MAS

解決辦法:SET GLOBAL server_id=2;

參考部落格:https://www.cnblogs.com/l-hh/p/9922548.html

https://www.cnblogs.com/sustudy/p/4174189.html

繼續閱讀