1.mysql5.7 yum源
rpm -ivh https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
2.yum安装mysql
yum install mysql-community-server
3.修改mysql初始密码
修改配置文件 vim /etc/my.cnf
开启安全模式 在配置文件中加入 skip-grant-tables
加入 sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
mysql -uroot -p
update mysql.user set host='%',authentication_string=password('123456'),password_expired='N',password_last_changed=now() where user = 'root';
flush privileges;
exit;
4.开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
5. 主配置
vim /etc/my.cnf
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
mysql -uroot -p
grant replication slave on *.* to 'backup'@'%' identified by '123456';
show master status;
6. 从配置
vim /etc/my.cnf
log-bin=mysql-bin
server-id=2
mysql -uroot -p
stop slave;
change master to master_user='backup',master_password='123456',master_host='192.168.1.80',master_port=3306,master_log_file='mysql-bin.000003',master_log_pos=1159; start slave;
show slave status\G; #查看主从