标签:process 初始化 启动数据库 restart base atp roo mamicode 图片
环境server-id=1
log-bin=mysql-bin
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重新启动数据库
systemctl restart mysqld
systemctl status mysqld
建立同步账号
mysql> grant replication slave on . to tongbu@‘%‘ identified by ‘P@ssw0rd‘;
mysql> flush privileges;
锁住数据库并查看bin-log状态
mysql> flush tables with read lock;
mysql> show master status\G;
设置第二台master
Master2配置
[root@master2 ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
server-id=2
log-bin=mysql-bin
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重新启动数据库
systemctl restart mysqld
systemctl status mysqld
执行change master
mysql> change master to master_host=‘192.168.1.81‘,master_user=‘tongbu‘,master_password=‘P@ssw0rd‘,master_log_file=‘mysql-bin.000001‘,MASTER_LOG_POS=591;
启动slave服务,并查看状态
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
查看操作清单
mysql> show processlist\G;
查看2台master之前的运作
netstat -natp |grep -i established.mysql
解析master2地址
此步骤要和dns做反向解析
yum -y install bind-utils
host 192.168.1.82
在master2上建立同步账号
mysql> grant replication slave on .* to tongbu@‘%‘ identified by ‘P@ssw0rd‘;
mysql> flush privileges;
执行查看语句
必须在本地建立应答脚本 .my.cnf
[root@master1 ~]# vi .my.cnfbr/>[client]
user=root
password=P@ssw0rd
mysql -e "show processlist\G;"
数据库解锁
mysql -e "unlock tables"
执行change master,实现多主复制
在master上执行show master status
在master2上执行show master status 查看bin-log
mysql> show master status;
在master1上执行change master
mysql> change master to master_host=‘192.168.1.82‘,master_user=‘tongbu‘,master_password=‘P@ssw0rd‘,master_log_file=‘mysql-bin.000001‘,MASTER_LOG_POS=154;
在master1上开启slave服务,并查看状态
mysql>start slave;
mysql> show slave status\G;
在master1上查看操作清单
mysql> show processlist;
查看参数
Master1
Master2
master1上新建数据看同步的结果
mysql> create database DB1;
在master2上新建数据看同步的结果
mysql> create database DB2;
标签:process 初始化 启动数据库 restart base atp roo mamicode 图片
原文地址:https://blog.51cto.com/huxiaoqiu/2539792