前不久工作不是很忙,把原先整理的mysql数据库的主导配置进度记录一下,有不足之处,请各位多多查对指教 

mysql主从配置详解(图像和文字),mysql主从详解图像和文字

近期职业不是很忙,把原先整理的mysql数据库的主导配置进度记录一下,有不足之处,请各位多多考订指教 

#环境配置#
master IP:192.168.46.137  slave IP:192.168.46.138  database:v1

壹.在两台机器,分别设置mysql数据库,分别增加远程连接权限

贰.安顿主数据库 

#编辑mysql的配置文件,增加以下内容#
vim etc/my.cnf
server-id=1
binlog-do-db=v1
relay-log=/var/lib/mysql/mysql-relay-bin
relay-log-index=/var/lib/mysql/mysql-relay-bin.index
log-error=/var/lib/mysql/mysql.err
master-info-file=/var/lib/mysql/mysql-master.info
relay-log-info-file=/var/lib/mysql/mysql-relay-log.info
log-bin=/var/lib/mysql/mysql-bin
编辑完成后,重启mysql,systemctl restart mysqld.service(centos7 直接使用systemctl命令)
创建一个复制用户,具有replication slave 权限
grant replication slave on *.* to 'user3'@'192.168.46.138' identified by 'user3';
用户名:user3  密码:user3
flush privileges;
#查看主库状态#
show master status;

  4503.com 1

记住FileSet和Position参数值,后面步骤会用到

叁.布局从数额库 

#编辑从数据库配置文件,添加以下内容#
vim etc/my.cnf
server-id=2
replicate-do-db=v1
relay-log=/var/lib/mysql/mysql-relay-bin
relay-log-index=/var/lib/mysql/mysql-relay-bin.index
log-error=/var/lib/mysql/mysql.err
master-info-file=/var/lib/mysql/mysql-master.info
relay-log-info-file=/var/lib/mysql/mysql-relay-log.info
log-bin=/var/lib/mysql/mysql-bin
注意:两个数据库配置文件里的server-id不能相同
重启mysql
mysql -u root -pxxx
change master to master_host='192.168.46.137',master_user='user3',master_password='user3',master_log_file='mysql-bin.000003',master_log_pos=120;
#启动slave线程#
start slave;
# 查看slave状态,注意G后面没有分号#
show slave status\G

  4503.com 2
 
水泥灰箭头所指五个参数,借使都为Yes,表明配置成功,尽管Slave_IO_Running为connecting,请检查防火墙,端口是不是开放,FIle,Position参数是还是不是同样,互连网是还是不是通畅等

到此,mysql主从配置完成,可以新增数据查看是否同步了

近年来职业不是很忙,把原先整理的mysql数据库的中坚配置进程记录一下,有不足之处,请各位多…

#环境配置#
master IP:192.168.46.137  slave IP:192.168.46.138  database:v1

4503.com,一.在两台机械,分别安装mysql数据库,分别增多远程连接权限

二.安插主数据库 

#编辑mysql的配置文件,增加以下内容#
vim etc/my.cnf
server-id=1
binlog-do-db=v1
relay-log=/var/lib/mysql/mysql-relay-bin
relay-log-index=/var/lib/mysql/mysql-relay-bin.index
log-error=/var/lib/mysql/mysql.err
master-info-file=/var/lib/mysql/mysql-master.info
relay-log-info-file=/var/lib/mysql/mysql-relay-log.info
log-bin=/var/lib/mysql/mysql-bin
编辑完成后,重启mysql,systemctl restart mysqld.service(centos7 直接使用systemctl命令)
创建一个复制用户,具有replication slave 权限
grant replication slave on *.* to 'user3'@'192.168.46.138' identified by 'user3';
用户名:user3  密码:user3
flush privileges;
#查看主库状态#
show master status;

  4503.com 3