mysql主从配置

时间:2022-01-13 15:01:50

引言:
  双11,阿里云服务器打折,于是我忍不住又买了一台服务器,于是咱也是有两台服务器的爷们了,既然有了两台服务器,那么肯定要好好利用一下吧,那么就来玩玩mysql的主从配置吧。

准备
  两台数据库服务器,从数据库服务器等级必须要大于等于主数据库服务器,
  我的主服务器是mysql的版本是,mysql5.6.33,ip地址假定为192.168.10.10

  从服务器是mysql5.7.15,ip地址假定为192.168.10.11

首先
    因为mysql主从配置的原理是利用远程通信,读取二进制文件日志,然后从数据库按照日志进行响应的操作,因此第一件需要做的事情就是开启二进制日志
    正常情况下,mysql 的配置文件的位置是/etc/my.cnf,使用命令

  vim /etc/my.cnf

然后在[mysqld]下添加,(已经开启的情况下,就不用添加了)

  server-id = 1 #server-id必须唯一,切记不能和从服务器相同,各个从服务器之间也不能相同
  log_bin = mysql-bin

然后
  因为我的数据不是空的,主从配置必须要两个数据库数据初始一直才可以配置

  所以我要把数据导出,然后手动的导入到从数据库才可以( 如果两台数据库都是空的,则跳过这一步),由于主数据库可能会一直有写入数据的情况

  所以配置之前,可能要选择宕机或者是迁移,我这里是选择了宕机维护

  使用以下命令导出所有的数据库

  mysqldump -uroot -p --all-databases>back.sql

  然后使用scp 命令把备份文件拷贝到从数据库服务器

  scp back.sql root@192.168.10.11:~/

  接着在从服务器中,先使用mysql命令登陆数据库,然后使用source命令导入数据

   source ~/back.sql

  这样就保持两个数据库的数据一致了

接下来
  在主数据库服务器中,使用grant命令添加从服务器帐号,grant命令就是mysql用来管理用户权限的

  ps:其实直接对mysql数据库的user表进行操作也是可以的,只不过直接操作的用户需要重启mysql服务才会生效,而grant则不需要,添加直接就能用了
  grant详细用法可以查询一下官方的手册,我这里就直接进行配置了(因为是服务器环境,所有所在的操作全在命令行执行,可视化工具有更简单的方法,这里不做介绍)
  使用以下命令,添加从服务器,登陆账户为crisen,密码为123456,地址任意

GRANT REPLICATION SLAVE ON *.* to 'crisen'@'%' identified by ''

接着使用命令show master status 查看当前主数据库服务器的状态

show master status\G

这里只有两个字段需要注意一下,一个是File,另一个是Position,因为这两个数据是需要给从服务器配置的
    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjoAAACcCAIAAAD58JZNAAAdFElEQVR4Ae2dS2/rSHbH617cb5DcRSAJjm+CoAOtkgBRFDg9VjCYPIZIkEALLXyXkyzsQRYC0jKQBNlZG+3kxSCZB2Jj4EwrmU6ivbwwYOgDCOhVGxe2Vv0dxjmnikUWxSJFUqJEin/idpssVp3Hr6g6PFUUJZrf+9vf/e7f/Md//d/7D58JbCAAAiAAAiBQSAJvf/WrVzKM/8MGAiAAAiAAAkUl8LaohsEuEAABEAABEPAJcLh6RXLlA8EeCIAACIBAEQm8pVj1qv4ronmwCQRAAARAAASYwFvEKlwIIAACIAACxSdQxLWr5vntzN1uz5tBhs6QzgydYOG2jqzC46zJrJg0hVzLLAwNQQAEQKAKBH7nT/+a/v1s8r/qQXYzGvDoHT+oGkM5RRFV1y/z26YbnUmCNSBZo8m2+yhSCVnlO7Sp1nRANtWWtP3OrEquKHnNpE6iHgiAQEkJvFu1e7lctk4cMZ0K56S+XK6eNo+b55ftx4vO9cIvpDF93H0Zdc6mQtBIM74VF2fmeb9m6j1n2K9PgtpSy0jQYDroiOGsP3SmA/IBGwiAAAiAQDEIyMlAWr/yt8fHOccrjlaPjy9czvlSILFwb3mPGzW/mdxrnrZry8mNGueng9G81j5dmc1baZH0sHnea83vzMgnjXDceUPfPCrWm07RImpKv9y6uqo0Z3ozkSE72rZUmRbj01tAz/Fa48N6nKHvasA+WfVcJcdKo9JlaveamoWqmsTWb4lad6xs9Sw16rplVJf2NGivYsAc98Bo7E7hRikyayo7I2pSsfaD27jqzea+RarUP7aZiDIQAIGyEODJwM5f/WzyP+5kIA0FNCAMHTku6sHRGBdk9NLjhRxRaHjTAwIf630C4DUzhpgEXKiZIUQ1CEuQuv2BTbZghdo2f99WUyZ/ZtWARs9ww1oq0/W5lKvo+U+jVniXtAdkyxo2k3yD/TsEt7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9Of/Tzifm9q5LYvlMz5cOExuOKO1W+iTI2PP5xyk2koy0IgAAI7IYAf+9KPW2xG33l1UJrSJ2RoIyzTCGLQ1Wfnt1M8vhjebsGloMACFSCwK/93ueUYP3o518iu6pEf8NJEAABECgnAf1kYDmth9UgAAIgAAIVIaCfDDSetqiI53ATBEAABECgRAS87ArxqkS9BlNBAARAoHIE9DsDK+c4HAYBEAABECgTAUwGlqm3YCsIgAAIVJaAG64q6z8cBwEQAAEQKAWB/wcmGH8Un+PIyQAAAABJRU5ErkJggg==" alt="" />

最后

  进入从服务器,先使用命令行登陆,然后使用命令
  192.168.10.10是主数据库的地址,crisen则是之前创建的帐号,123456自然就是密码了,这里还有两个参数,则需要上一步中file的值 mysql-bin.000005,与position的值5677570

 change master to master_host='192.168.10.10',master_user='crisen',master_password='',master_log_file='mysql-bin.000005',master_log_pos=5677570;

  然后在使用start slave命令,启动从服务器即可

start slave;

  接着使用命令 show slave status\G,查看从服务器状态

show slave status\G

  如果出现下面两个字段都为yes

  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes

尾语

  mysql数据库的主从配置很简单,只要linux下命令行操作以及一些mysql的基本知识就可以很轻松的完成了,但是想象永远都是想象,只有你亲自去尝试了,你才会明白的更加深刻

  I hear I forget,I see I recongnised,I do I understand!