Mysql主主架构

Mysql主主架构

主机环境

主mysql的信息:
主机名:centos-41
ip地址:10.0.0.41
从mysql的信息:
主机名:centos-42
ip地址:10.0.0.42

主mysql的操作

1.安装mysql的客户端和服务端

[root@ localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@ localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@ localhost ~]# yum -y install mysql-community-server
[root@ localhost ~]# chown -R root:root /var/lib/mysql
[root@ localhost ~]# systemctl restart mysqld

2.修改mysql密码

[root@ localhost ~]# mysql_secure_installation


3.修改配置文件

[root@ localhost ~]# vim /etc/my.cnf
[mysqld]
server-id = 1
log-bin = mysql-bin
relay-log = relay-bin

4.创建同步的用户

[root@ localhost ~]#mysql -uroot -p123
mysql> grant all on *.* to 'tongbu'@'10.0.0.%' identified by '123456';
mysql> flush privileges;

5.查看主服务器状态

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 |      470 |              |                  |
+------------------+----------+--------------+------------------+

从mysql的操作

1.安装mysql的客户端和服务端

[root@ localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@ localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@ localhost ~]# yum -y install mysql-community-server
[root@ localhost ~]# chown -R root:root /var/lib/mysql
[root@ localhost ~]# systemctl restart mysqld

2.关闭slave

[root@ localhost ~]# mysql -uroot -p123
mysql> stop slave;

3.指向 c6m01的master

mysql> change master to master_host='10.0.0.41',
master_user='tongbu',
master_password='123',
master_log_file='mysql-bin.000003',
master_log_pos=470;

4.开启slave并查看状态

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

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.41
                  Master_User: tongbu
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 470
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值