安装MySQL:(主从同步)
[root@localhost ~]# yum -y install mariadb mariadb-server
关闭防火墙和selinux:(主从同步)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
修改主配置文件(主):
[root@localhost ~]# vim /etc/my.cnf
#mysqld模块添加两行
server-id=1
log-bin=mysql-marter-bin
重启mysql:
[root@localhost ~]# systemctl restart mariadb
进入mysql并设置:
[root@localhost ~]# mysql
MariaDB [(none)]> grant all on *.* to yl@'%' identified by 'yl';
MariaDB [(none)]> show master status;
+-------------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------------+----------+--------------+------------------+
| mysql-marter-bin.000003 | 365 | | |
+-------------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
修改主配置文件(从):
[root@localhost ~]# vim /etc/my.cnf
#mysqld模块添加两行
server-id=2
log-bin=mysql-server-bin
relay-log=relay-server-log
重启mysql:
[root@localhost ~]# systemctl restart mariadb
进入mysql并设置:
[root@localhost ~]# mysql
MariaDB [(none)]> change master to master_host='192.168.136.162',master_user='yl',master_password='yl',master_log_file='mysql-marter-bin.000003',master_log_pos=365;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.136.162
Master_User: yl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-marter-bin.000003
Read_Master_Log_Pos: 365
Relay_Log_File: relay-server-log.000002
Relay_Log_Pos: 536
Relay_Master_Log_File: mysql-marter-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes