使用yum安装部署mysql两台
[root@localhost ~]# yum -y install mariadb mariadb-server
查看mysql的版本信息
[root@localhost ~]# mysql -V
配置两台mysql
[root@localhost ~]# vim /etc/my.cnf
server-id=1
log-bin=mysql-master-bin
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysqladmin -uroot password mysql
[root@localhost ~]# mysql -uroot -pmysql
MariaDB [(none)]> grant all on . to tom@’%’ identified by ‘tom’;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status;
±------------------------±---------±-------------±-----------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
±------------------------±---------±-------------±-----------------+
| mysql-master-bin.000001 | 442 | | |
±------------------------±---------±-------------±-----------------+
1 row in set (0.00 sec)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# vim /etc/my.cnf
server-id=2
log-bin=mysql-server-bin
relay-bin=relays-server-bin
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin -uroot password mysql
[root@localhost ~]# mysql -uroot -pmysql
MariaDB [(none)]> change master to master_host=‘192.168.33.136’,
-> master_user=‘tom’,
-> master_password=‘tom’,
-> master_log_file=‘mysql-master-bin.000001’,
-> master_log_pos=442;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.33.136
Master_User: tom
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-master-bin.000001
Read_Master_Log_Pos: 442
Relay_Log_File: relay-server-log.000002
Relay_Log_Pos: 536
Relay_Master_Log_File: mysql-master-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes