MySQL Replication Configuration
在一臺linux伺服器上實現MySQL Replication
配置說明:
master:
version 5.1.47
/etc/my47.cnf
server-id = 1
port = 3307
socket = /tmp/mysql47.sock
datadir = /mysql47/data
binlog-do-db = test(複製庫名)
master:
version 5.1.47
/etc/my47.cnf
server-id = 1
port = 3307
socket = /tmp/mysql47.sock
datadir = /mysql47/data
binlog-do-db = test(複製庫名)
slave:
version 5.1.48
/etc/my48.cnf
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
datadir = /usr/local/mysql/var
replicate-do-db = test(與master的binlog-do-db二選一即可)
version 5.1.48
/etc/my48.cnf
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
datadir = /usr/local/mysql/var
replicate-do-db = test(與master的binlog-do-db二選一即可)
1.在master上建立複製使用者
$ mysqld_safe --defaults-file=/etc/my47.cnf &
$ mysql -S /tmp/mysql47.sock -p
mysql> create user rep@localhost identified by 'rep';
$ mysqld_safe --defaults-file=/etc/my47.cnf &
$ mysql -S /tmp/mysql47.sock -p
mysql> create user rep@localhost identified by 'rep';
mysql> GRANT replication slave ON *.* to 'rep'@'localhost';
2.分別配置master和slave的my.cnf引數
master:
# vi /etc/my47.cnf
[mysqld]
server-id = 1
socket = /tmp/mysql47.sock
port = 3307
datadir = /mysql47/data
log-bin=mysql-bin
#binlog-do-db = test
master:
# vi /etc/my47.cnf
[mysqld]
server-id = 1
socket = /tmp/mysql47.sock
port = 3307
datadir = /mysql47/data
log-bin=mysql-bin
#binlog-do-db = test
slave:
# vi /etc/my48.cnf
[mysqld]
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
#log-bin=mysql-bin
#log-slave-updates
#read-only=1
replicate-do-db=test
# vi /etc/my48.cnf
[mysqld]
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
#log-bin=mysql-bin
#log-slave-updates
#read-only=1
replicate-do-db=test
3.slave上配置master資訊
execute the following statement on the slave:
$ mysqld_safe --defaults-file=/etc/my48.cnf &
$ mysql -S /tmp/mysql48.sock -p
mysql> CHANGE MASTER TO
-> MASTER_HOST='localhost',
-> MASTER_PORT=3307,
-> MASTER_USER='rep',(前面建立具有複製許可權的那個使用者)
-> MASTER_PASSWORD='rep',
-> MASTER_LOG_FILE='mysql-bin.000014',
-> MASTER_LOG_POS=106;
其中MASTER_LOG_FILE='mysql-bin.000014',MASTER_LOG_POS=106引數出自master
master執行:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 | 106 | | |
+------------------+----------+--------------+------------------+
execute the following statement on the slave:
$ mysqld_safe --defaults-file=/etc/my48.cnf &
$ mysql -S /tmp/mysql48.sock -p
mysql> CHANGE MASTER TO
-> MASTER_HOST='localhost',
-> MASTER_PORT=3307,
-> MASTER_USER='rep',(前面建立具有複製許可權的那個使用者)
-> MASTER_PASSWORD='rep',
-> MASTER_LOG_FILE='mysql-bin.000014',
-> MASTER_LOG_POS=106;
其中MASTER_LOG_FILE='mysql-bin.000014',MASTER_LOG_POS=106引數出自master
master執行:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 | 106 | | |
+------------------+----------+--------------+------------------+
檢視slave狀態:
mysql> slave start;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: rep
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 193
Relay_Log_File: oel5-relay-bin.000013
Relay_Log_Pos: 338
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
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: 193
Relay_Log_Space: 637
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:
Slave_IO_Running、Slave_SQL_Running狀態為YES
mysql> slave start;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: rep
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 193
Relay_Log_File: oel5-relay-bin.000013
Relay_Log_Pos: 338
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
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: 193
Relay_Log_Space: 637
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:
Slave_IO_Running、Slave_SQL_Running狀態為YES
mysql> show processlist\G;
檢視複製程式
檢視複製程式
4.Replication驗證
master:
mysql> use test;
mysql> create table t (i int);
mysql> insert into t values(10);
mysql> insert into t values(20);
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
master:
mysql> use test;
mysql> create table t (i int);
mysql> insert into t values(10);
mysql> insert into t values(20);
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
slave:
mysql> use test;
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
mysql> use test;
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17997/viewspace-668384/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Build mysql replicationUIMySql
- MySQL Group ReplicationMySql
- MySQL基於GTIDs的MySQL ReplicationMySql
- Mysql replication check指令碼MySql指令碼
- MySQL group replication介紹MySql
- An Overview of PostgreSQL & MySQL Cross ReplicationViewMySqlROS
- Mysql Replication學習記錄MySql
- MYSQL Group Replication搭建過程記錄MySql
- MGR(MySQL Group Replication)部署搭建測試MySql
- 【MySQL】MySQL Replication 一主一備搭建步驟(GTID方式)MySql
- MySQL8.0.16新特性:The Communication Protocol In Group ReplicationMySqlProtocol
- 【MySQL】MySQL Replication 一主一備搭建步驟(傳統方式)MySql
- 配置Mysql Group Replication遇到的問題筆記MySql筆記
- Mysql 5.7 基於組複製(MySQL Group Replication) - 運維小結MySql運維
- MySQL 8.0 Reference Manual(讀書筆記90節--Replication)MySql筆記
- Geo-replication: 從 Copysets 到 Tiered Replication
- MySQL 8.0 Reference Manual(讀書筆記94節--Replication(5))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記93節--Semisynchronous Replication)MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記92節--Replication(3))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記91節--Replication(2))MySql筆記
- Mysql 建立心跳錶來監控Replication的Slave是否延遲MySql
- HBase Replication詳解
- redis configurationRedis
- MySQL 8.0 Reference Manual(讀書筆記69節--InnoDB Startup Configuration)MySql筆記
- How to Optimize PostgreSQL Logical ReplicationSQL
- 使用ProxySQL實現MySQL Group Replication的故障轉移、讀寫分離(一)MySql
- openwrt advanced configuration
- etcd install & configuration
- MySQL 8.0 Reference Manual(讀書筆記77節--Merge Threshold for Index Pages & Automatic Configuration for a Dedicated MySQL Server)MySql筆記IndexServer
- 9.(轉)Spring Configuration Check Unmapped Spring configuration files foundSpringAPP
- MySQL 8.0 Reference Manual(讀書筆記70節--InnoDB Buffer Pool Configuration (1))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記71節--InnoDB Buffer Pool Configuration (2))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記72節--InnoDB Buffer Pool Configuration (3))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記74節--Spin Lock Polling & Purge Configuration)MySql筆記
- Replication (Part 2): Transactions, Consistency and Consensus
- Redis replication 中的探活Redis
- Redis 主從複製(Replication)Redis
- .net core Configuration物件物件
- spring 解析 @Configuration 流程Spring