------------------------------------------------------------------------------
mysql 复制特性应用(类似停机方式搭建master-slave)
分别在两台服务器上采用rpm方式安装了两套mysql
------------------------------------------------------------------------------
在master节点修改my.cnf
vi /etc/my.cnf
添加:
server_id = 10086
log-bin=/var/log/mysql/binlog/mysql-bin
在slave节点修改my.cnf
vi /etc/my.cnf
添加:(slave节点可选择不配置binlog)
server_id = 10087
修改过my.cnf后,需重启mysql服务。
--------------------------------------------------------------------------------
master上创建复制用户
grant replication slave on *.* to 'repl'@'32.114.67.%' identified by '!QAZ2wsx';
----
change master to
master_host='32.114.67.178',
master_port=3306,
master_user='repl',
master_password='!QAZ2wsx',
master_log_file='mysql-bin.000001',
master_log_pos=447;
mysql> change master to
-> master_host='32.114.67.178',
-> master_port=3306,
-> master_user='repl',
-> master_password='!QAZ2wsx',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=447;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
mysql>
-------------------------------------------------------------------------------
启动slave端应用服务
start slave;
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
---------------------
环境测试,
在master点创建表,并插入数据,
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> create table test (id int,name varchar(100));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into test values(1,'killvoon');
Query OK, 1 row affected (0.01 sec)
--------------------------------------------------------------------------------
在slave节点查看是否存在该表及数据
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test |
+----------------+
1 row in set (0.00 sec)
mysql> select * from test;
+------+----------+
| id | name |
+------+----------+
| 1 | killvoon |
+------+----------+
1 row in set (0.00 sec)
发现,在slave点确实存在该表了。说明slave环境搭建成功。
-----------------------------------------------------------------------------
如果发现slave节点没有同步到数据,使用命令show slave status\G 查看
关注Slave_IO_State 信息
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 32.114.67.178
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 1056
Relay_Log_File: oemcs3-relay-bin.000002
Relay_Log_Pos: 929
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 1056
Relay_Log_Space: 1137
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 10086
Master_UUID: 7b288cbd-df02-11e7-b967-0050569a4396
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
mysql>
------------------------------------------------------------------------
将slave节点的应用停掉,然后在master点做操作,再将slave节点应用打开,看看是否可以"续传":
slave节点:
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
master节点:
mysql> insert into t values(2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values(3);
Query OK, 1 row affected (0.01 sec)
mysql> select * from t;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
slave节点:由于slave应用没启动,所以没有数据同步
mysql> select * from t;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
开启slave应用:数据立马过来
start slave;
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
-----------------------------------------------------------------------------------------------------------
小结:我的搭建方式是最为简单且理想化的,没有考虑master点不可停机的情况。
即便如此,相对于oracle dataguard,依然是相当简化。
至于其他同步问题,还需在使用过程中慢慢品味。
当然,下一步需要学习如何实时在线做slave。
mysql 复制特性应用(类似停机方式搭建master-slave)
分别在两台服务器上采用rpm方式安装了两套mysql
------------------------------------------------------------------------------
在master节点修改my.cnf
vi /etc/my.cnf
添加:
server_id = 10086
log-bin=/var/log/mysql/binlog/mysql-bin
在slave节点修改my.cnf
vi /etc/my.cnf
添加:(slave节点可选择不配置binlog)
server_id = 10087
修改过my.cnf后,需重启mysql服务。
--------------------------------------------------------------------------------
master上创建复制用户
grant replication slave on *.* to 'repl'@'32.114.67.%' identified by '!QAZ2wsx';
----
change master to
master_host='32.114.67.178',
master_port=3306,
master_user='repl',
master_password='!QAZ2wsx',
master_log_file='mysql-bin.000001',
master_log_pos=447;
mysql> change master to
-> master_host='32.114.67.178',
-> master_port=3306,
-> master_user='repl',
-> master_password='!QAZ2wsx',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=447;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
mysql>
-------------------------------------------------------------------------------
启动slave端应用服务
start slave;
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
---------------------
环境测试,
在master点创建表,并插入数据,
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> create table test (id int,name varchar(100));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into test values(1,'killvoon');
Query OK, 1 row affected (0.01 sec)
--------------------------------------------------------------------------------
在slave节点查看是否存在该表及数据
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| test |
+----------------+
1 row in set (0.00 sec)
mysql> select * from test;
+------+----------+
| id | name |
+------+----------+
| 1 | killvoon |
+------+----------+
1 row in set (0.00 sec)
发现,在slave点确实存在该表了。说明slave环境搭建成功。
-----------------------------------------------------------------------------
如果发现slave节点没有同步到数据,使用命令show slave status\G 查看
关注Slave_IO_State 信息
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 32.114.67.178
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 1056
Relay_Log_File: oemcs3-relay-bin.000002
Relay_Log_Pos: 929
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 1056
Relay_Log_Space: 1137
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 10086
Master_UUID: 7b288cbd-df02-11e7-b967-0050569a4396
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
mysql>
------------------------------------------------------------------------
将slave节点的应用停掉,然后在master点做操作,再将slave节点应用打开,看看是否可以"续传":
slave节点:
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
master节点:
mysql> insert into t values(2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t values(3);
Query OK, 1 row affected (0.01 sec)
mysql> select * from t;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
slave节点:由于slave应用没启动,所以没有数据同步
mysql> select * from t;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
开启slave应用:数据立马过来
start slave;
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
-----------------------------------------------------------------------------------------------------------
小结:我的搭建方式是最为简单且理想化的,没有考虑master点不可停机的情况。
即便如此,相对于oracle dataguard,依然是相当简化。
至于其他同步问题,还需在使用过程中慢慢品味。
当然,下一步需要学习如何实时在线做slave。