视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
MySQL互为主备的简单搭建
2020-11-09 10:50:02 责编:小采
文档


MySQL 互为主备的简单搭建 192.168.190.128《====》192.168.190.129 master----》slave slave《----master 1.在master 128 上配置

MySQL 互为主备的简单搭建

192.168.190.128《====》192.168.190.129
master----》slave
slave《----master

1.在master 128 上配置my.cnf文件,添加下列参数:
server-id=1
log-bin=mysql-bin
log-salve-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1

重新启动mysql
[root@calvin1 ~]# /etc/init.d/mysqld start
Starting MySQL: [ OK ]
[root@calvin1 ~]# mysql -u root -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.77-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| calvin |
| calvin2 |
| mysql |
| sampdb |
| test |
| testdb |
+--------------------+
7 rows in set (0.00 sec)

2.在master 129 上配置my.cnf文件,,添加下列参数:
server-id=2
log-bin=mysql-bin
log-salve-updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2

重新启动mysql
[root@calvin2 ~]# /etc/init.d/mysqld start
Starting MySQL: [ OK ]
[root@calvin2 ~]# mysql -u root -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| calvin |
| calvin2 |
| mysql |
| sampdb |
| test |
| testdb |
+--------------------+
7 rows in set (0.00 sec)

3.在在master 128上创建复制账号:
mysql> grant replication slave,file on *.* to mysync@'192.168.190.129' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

对所有表添加只读锁:
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

查看master二进制文件,pos号:
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 906
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

4.在在master 129上创建复制账号:
mysql> grant replication slave,file on *.* to mysync@'192.168.190.128' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

对所有表添加只读锁:
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

查看master二进制文件,pos号:
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 318
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)



5.修改同步参数:
根据第3步读取的二进制文件和pos号,配置master 128的同步参数:
mysql> change master to
-> master_host='192.168.190.129',
-> master_user='mysync',
-> master_password='123456',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=318;
Query OK, 0 rows affected (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

根据第4步读取的二进制文件和pos号,配置master 129的同步参数:
mysql> change master to
-> master_host='192.168.190.128',
-> master_user='mysync',
-> master_password='123456',
-> master_log_file='mysql-bin.000004',
-> master_log_pos=906;
Query OK, 0 rows affected (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

下载本文
显示全文
专题