萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> 簡單的MySQL數據庫主從同步配置

簡單的MySQL數據庫主從同步配置

   Master配置:

 代碼如下  

log-bin = mysql-bin
server-id = 1
binlog-do-db = powerdns #要同步的數據庫

  Master新增slave賬號:

 代碼如下  

mysql> GRANT replication slave ON *.* TO 'slave'@'192.168.1.2' IDENTIFIED BY 'passwd'; 
mysql> FLUSH privileges;

  重啟Master MySQL,查看Master狀態信息,記住File名稱,POS位置。

 代碼如下  

mysql> show master status; 
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      309 | powerdns     | mysql            |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

  Slave配置:

 代碼如下  

server-id =2

  開始同步:

 代碼如下  

mysql> CHANGE master TO master_host='192.168.1.1',master_user='slave',master_password='passwd',
master_log_file='mysql-bin.000002',master_log_pos=309; 
mysql> START slave;

  查看Slave同步狀態:

 代碼如下  

mysql> SHOW slave STATUSG;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

copyright © 萬盛學電腦網 all rights reserved