两台linux虚拟主机
Linux版本CentOS7.4、MySQL 5.7
ip:192.168.3.100、192.168.3.108
3.1、1. 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@BrianZhu /]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@BrianZhu /]# yum -y install mysql-community-server
[root@BrianZhu /]# systemctl start mysqld.service
[root@BrianZhu /]# systemctl status mysqld.service
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
[root@BrianZhu /]# grep "password" /var/log/mysqld.log
这时候我们要把密码规则改一下,执行下面sql就可以了:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;一、配置master
master配置:
cat /etc/my.cnf
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pidlog-bin=mysql-binserver_id=226bind-address=0.0.0.0授权账户
GRANT REPLICATION SLAVE ON *.* to 'tom'@'%' identified by '123456';
第二步:
查看192.168.3.100MySQL服务器二进制文件名与位置 mysql>SHOW MASTER STATUS;
二 、salve 配置
cat /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pidlog-bin=mysql-binserver_id=220
在salve 执行如下语句:
change master to master_host='192.168.3.100',master_user='tom',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=1904;mysql>START SLAVE; #开启复制
mysql>SHOW SLAVE STATUS\G #查看主从复制是否配置成功
当看到Slave_IO_Running: YES、Slave_SQL_Running: YES才表明状态正常
三、测试主从复制是否成功
192.168.3.100主MySQL操作(master):
mysql>create database aa;
mysql>use aa;
mysql>create table tab1(id int auto_increment,name varchar(10),primary key(id));
mysql>show databases;
mysql>show tables;
192.168.3.104从MySQL操作:
mysql>show databases;
mysql>show tables;
上面两个结果图可得知,两主机达到了数据同步。主从复制的配置就是如此的简单