首页> 知识分享 >其它分享 其它分享

MySQL主从同步

作者:小萝卜 2019-06-04 浏览 1333

简介MySQL主从同步,1、Master配置(1)数据库授权:mysql> grant replication slave on *.* to slaveuser@"192.168.4.12" identified by "123456";

##################MySQL主从同步#################################

1、Master配置

(1)数据库授权:

mysql> grant replication slave on *.* to slaveuser@"192.168.4.12" identified by "123456";

(2)启用binlog日志:

      [root@10 ~]# vim /etc/my.conf

      [mysqld]

      server_id=10        #指定主MySQL数据库的ID

      log-bin=master10     #启用binglog日志,日志文件保存在MySQL的安装主目录(/var/lib/mysql)下,文件名的格式为"master10.000001"(每个文件最大容量500M,超过500M或者重启MySQL服务后自动生成下一个日志文件)

      (3)查看master状态:

mysql>show master status\G;

 

2、Slave配置:

(1)配置server_id:

        [root@20 ~]# vim /etc/my.conf

        [mysqld]

        server_id=20        #指定从MySQL数据库的ID

(2)配置主数据库信息(使用本机的root用户登陆)

       mysql>change master to master_host="192.168.4.10",             

             master_user="slaveuser",

             master_password="123456",

             matser_log_file="master10.000001",

             master_log_pos=154;

(3)开启slave状态

             mysql> start slave;

(4)检查slave状态

             mysql> show slave status\G;

 命令执行结果中下面两项显示如下则说明主从同步配置正常

               Slave_IO_Running:Yes

               Slave_SQL_Running:Yes

3、验证:

    在主数据库(192.168.4.10)上面进行数据添加删除等操作,在从数据库上面(192.168.4.20)及时就能看到。

 

很赞哦! (0)

文章评论

    高端网站建设