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