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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL Group ReplicationMySql
- Build mysql replicationUIMySql
- Mysql Replication(轉)MySql
- MySQL案例-replication"卡死"MySql
- 【MySQL】Semisynchronous Replication 概述MySql
- MySQL Replication淺析MySql
- On MySQL replication, again…MySqlAI
- 【Mysql】MySQL5.7.17- Group Replication搭建MySql
- An Overview of PostgreSQL & MySQL Cross ReplicationViewMySqlROS
- Mysql replication check指令碼MySql指令碼
- MySQL group replication介紹MySql
- MySQL Group Replication小試MySql
- mysql replication之GTIDMySql
- MySQL基於GTIDs的MySQL ReplicationMySql
- mysql replication /mysql 主從複製原理MySql
- 【MySql】MySQL Replication Fatal Error 1236MySqlError
- Mysql Replication學習記錄MySql
- 理解 MySQL(3):複製(Replication)MySql
- MySQL now supports an interface for semisynchronous replication:MySql
- mysql replication常見錯誤MySql
- MySQL Group Replication 學習(部署篇)MySql
- MySQL Replication常見錯誤整理MySql
- mysql replication複製錯誤(zt)MySql
- MySQL Replication Fatal Error 1236MySqlError
- 【MySQL】Slave can not handle replication events with the checksum ...MySql
- MYSQL Group Replication搭建過程記錄MySql
- MGR(MySQL Group Replication)部署搭建測試MySql
- MYSQL並行複製(parallel replication部署篇)MySql並行Parallel
- 【MySQL】Semisynchronous Replication 配置和引數說明MySql
- 【MySQL】5.7版本 Semisync Replication 增強MySql
- 【MySQL】MySQL Replication 一主一備搭建步驟(GTID方式)MySql
- 【MySQL】MySQL Replication 一主一備搭建步驟(傳統方式)MySql
- 配置Mysql Group Replication遇到的問題筆記MySql筆記
- MySQL Replication的複製執行緒介紹MySql執行緒
- Database(Mysql、Sqlserver) Configuration Security ReinforcementDatabaseMySqlServer
- Mysql 5.7 基於組複製(MySQL Group Replication) - 運維小結MySql運維
- MySQL8.0.16新特性:The Communication Protocol In Group ReplicationMySqlProtocol
- MySQL 5.7組複製(group replication)的要求和限制MySql