标签:master/slave mysql 双主复制 mariadb
例、主库192.168.110.128,从库192.168.110.130
master:
(1)、在主库上设置一个复制使用的账户并授予replication slave权限。
MariaDB [(none)]> grant replication slave on *.* to ‘repl_user‘@‘192.168.110.130‘ identified by ‘pancou‘;
Query OK, 0 rows affected (0.00 sec)
(2)、修改主数据库的配置文件my.cnf,,开启binlog,并设置server-id的值。这两个参数的修改需要重新启动服务才可以生效。
[mysqld]
log-bin=/data/logs/mysql-bin
relay-log=/data/logs/relay-bin
server-id = 1
log-slave-updates=ON #是为从库的写操作记录binlog
slave-skip-errors=all
auto_increment_increment=2
auto_increment_offset=1
(3)、对从库服务器做相应的设置
MariaDB [(none)]> change master to master_host=‘192.168.110.128‘, master_port=3306, master_user=‘repl_user‘, master_password=‘pancou‘, master_log_file=‘mysql-bin.000003‘, master_log_pos=3375615;
Query OK, 0 rows affected (0.06 sec)
(4)、在从库上,启动slave进程。
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.04 sec)
(5)、查看从库复制状态。
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.110.128
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 3375615
Relay_Log_File: www-relay-bin.000002
Relay_Log_Pos: 535
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
slave:
(1)、修改从数据库的配置文件my.cnf,,开启binlog,并设置server-id的值。这两个参数的修改需要重新启动服务才可以生效。
[mysqld]
log-bin=/data/logs/mysql-bin
relay-log=/data/logs/relay-bin
server-id = 2
log-slave-updates=ON
slave-skip-errors=all
auto_increment_increment=2
auto_increment_offset=2
(2)、在从库上设置一个复制使用的账户并授予replication slave权限。
MariaDB [(none)]> grant replication slave on *.* to ‘repl_user‘@‘192.168.110.128‘ identified by ‘pancou‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000007 | 525 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
(3)、在主库上进行设置
MariaDB [pancou]> change master to
-> master_host=‘192.168.110.130‘,
-> master_port=3306,
-> master_user=‘repl_user‘,
-> master_password=‘pancou‘,
-> master_log_file=‘mysql-bin.000007‘,
-> master_log_pos=525;
Query OK, 0 rows affected (0.02 sec)
(5)、在主库上,启动slave进程。
MariaDB [pancou]> start slave;
Query OK, 0 rows affected (0.00 sec)
(6)、查看主库复制状态
MariaDB [pancou]> show slave status\G
e
验证测试:
在从库上插入一些数据:
MariaDB [pancou]> insert into emp values(4,‘Bob‘),(5,‘Jack‘);
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
在主库上查看是否同步过来
MariaDB [pancou]> select * from emp;
+--------+----------+
| emp_id | emp_name |
+--------+----------+
| 1 | tom |
| 2 | jerry |
| 3 | Linda |
| 4 | Bob |
| 5 | Jack |
+--------+----------+
5 rows in set (0.00 sec)
本文出自 “linunx运维专题” 博客,请务必保留此出处http://lijianmin2008.blog.51cto.com/621678/1925089
标签:master/slave mysql 双主复制 mariadb
原文地址:http://lijianmin2008.blog.51cto.com/621678/1925089