首页 > 数据库技术 > 详细

mysql5.7搭建主从同步

时间:2020-06-08 23:55:17      阅读:80      评论:0      收藏:0      [点我收藏+]
主库 192.168.60.202 从库 192.168.60.203
主库搭建 mysql 5.7
yum clean all && yum makecache && yum install epel* -y
rpm -Uvh http://repo.mysql.com/mysql57-community-release-el7.rpm
yum clean all && yum makecache
yum install gcc gcc-c++ openssl-devel mysql mys
systemctl start mysqld&&systemctl enable mysqld
修改 /etc/my.cnf
[root@master ~]# cat /etc/my.cnf
[mysqld]
#

Remove leading # and set to the amount of RAM for the most important data

cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

#

Remove leading # to turn on a very important data integrity option: logging

changes to the binary log between backups.

log_bin

#

Remove leading # to set options mainly useful for reporting servers.

The server defaults are faster for transactions and fast SELECTs.

Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
server-id = 1 #唯一
log-bin=mysql-bin 开启 binlog
sync-binlog=1
validate_password_policy=0
validate_password_length=1
修改完重启
systemctl restart mysqld
过滤MySQL初始密码
cat /var/log/mysqld.log | grep ‘password is generated‘
安全加固
mysql_secure_installation
mysql主库做授权配置
mysql –uroot-p
mysql>grant replication slave on . to ‘repl_user‘@‘192.168.60.%‘ identified by ‘密码‘;
查看主库状态
技术分享图片

从库搭建mysql5.7
yum clean all && yum makecache && yum install epel* -y
rpm -Uvh http://repo.mysql.com/mysql57-community-release-el7.rpm
yum clean all && yum makecache
yum install gcc gcc-c++ openssl-devel mysql mys
systemctl start mysqld&&systemctl enable mysqld
修改 /etc/my.cnf
[root@slave ~]#vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
server-id = 2 和主库不一致即可
log-bin=mysql-bin
validate_password_policy=0
validate_password_length=6
修改完重启
systemctl restart mysqld
过滤MySQL初始密码
cat /var/log/mysqld.log | grep ‘password is generated‘
安全加固
mysql_secure_installation

从库登录mysql
mysql -uroot -p
mysql> set global read_only=1; 设置从库只读

mysql> change master to master_host=‘192.168.60.202‘,master_user=‘repl_user‘,master_password=‘密码‘,master_log_file=‘mysql-bin.000003‘,master_log_pos=154;

mysql>start slave;
从库 IO和SQL线程两个YES状态
技术分享图片

mysql5.7搭建主从同步

原文:https://blog.51cto.com/13293070/2502606

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!