MySQL master/slave

21ca發表於2016-12-30
Master my.ini
  1. basedir = D:\mysql_test\mysql-5.7.17-master
  2. datadir = D:\mysql_test\mysql-5.7.17-master\data
  3. port = 3306
  4. log-bin=mysql-bin
  5. server_id=1
  6. binlog-ignore-db=information_schema
  7. binlog-ignore-db=cluster
  8. binlog-ignore-db=mysql
  9. binlog-do-db=test
Slave my.ini
  1. basedir = D:\mysql_test\mysql-5.7.17-slave
  2. datadir = D:\mysql_test\mysql-5.7.17-slave\data
  3. port = 3307
  4. log-bin=mysql-bin
  5. server-id=2
  6. binlog-ignore-db=information_schema
  7. binlog-ignore-db=cluster
  8. binlog-ignore-db=mysql
  9. replicate-do-db=test
  10. replicate-ignore-db=mysql
  11. log-slave-updates
  12. slave-skip-errors=all
  13. slave-net-timeout=60
Master 執行
mysql> CREATE USER 'rep'@'%' IDENTIFIED BY 'rep';
mysql> GRANT FILE ON *.* TO 'rep'@'%' IDENTIFIED BY 'rep';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'rep'@'%' IDENTIFIED BY 'rep';
mysql> FLUSH PRIVILEGES;

mysql> show master status;
+------------------+----------+--------------+----------------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                 | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000002 |     4570 | test         | information_schema,cluster,mysql |                   |
+------------------+----------+--------------+----------------------------------+-------------------+


Slave 執行
mysql> CREATE USER 'rep'@'%' IDENTIFIED BY 'rep';
mysql> change master to master_host='localhost',master_user='rep',master_password='rep',master_log_file='mysql-bin.000002', master_log_pos=4570;

mysql> start slave;
mysql> show slave status;

Slave_IO_Running 和 Slave_SQL_Running都是 Yes 表示成功。

Master建立資料庫,建立表,新增資料,會自動複製到Slave。 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10742815/viewspace-2131666/,如需轉載,請註明出處,否則將追究法律責任。

相關文章