技术

mysql5.6安装与主从配置

July 19, 2018

安装mysql5.6
yum -y update
yum install wget -y
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server -y
chgrp -R mysql /var/lib/mysql
chmod -R 770 /var/lib/mysql
service mysql restart

主服务器配置
关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
编辑vi /etc/my.cnf,添加下面
[mysqld]
server-id = 1
log_bin = master-bin
log_bin_index = master-bin.index
binlog_do_db = my_data #需要做同步的数据库名称
binlog_ignore_db = mysql

mysql -u root
mysql>grant replication slave on . to '用户名' @'10.140.10.%' identified by '密码';
service mysql restart
mysql> show master status;

从服务器配置
关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
编辑vi /etc/my.cnf,添加下面
[mysqld]
server-id = 2
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index

service mysql restart
mysql -u root
mysql>change master to master_host='10.140.10.101',master_port=3306,master_user='用户名',master_password='密码',master_log_file='master-bin.000001',master_log_pos=120;
mysql>start slave;
mysql>show slave statusG
mysql.png

添加新评论