0

0

mysql主从复制_MySQL

php中文网

php中文网

发布时间:2016-06-01 13:47:08

|

1097人浏览过

|

来源于php中文网

原创

bitsCN.com  一、环境描述
主数据库服务器ip:192.168.0.2
从数据库服务器ip:192.168.0.3
主从服务器上的mysql已全新安装,但并为投入生产,所以无数据产生。
二、主从复制配置
 1.主数据库服务器master配置
  (1)为从服务器slave授权
   mysql> grant replication slave on *.* to slave@192.168.0.3 identified by "123";
   (2)查看master状态
   mysql> show master status;
 +------------------+----------+--------------+------------------+
 | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 +------------------+----------+--------------+------------------+
 | mysql-bin.000003 |      400 |              |                  |
 +------------------+----------+--------------+------------------+
 1 row in set (0.00 sec)
 记下file和position,一会配置slave会用到。(file为mysql日志的文件,position为日志的线索号,从服务器将从这么位置开始复制) 
 2.从数据库服务器slave配置
  (1)修改slave的server id,避免和其他mysql数据库的重复
   vi /etc/my.cnf
   server-id = 2
   (2)执行sql语句的同步
   mysql> change master to master_host=192.168.0.2, master_user=slave, master_password=123, master_log_file=mysql-bin.000003, master_log_pos=400;
   (3)启动slave的同步功能
   mysql> start slave;
    (4)查看slave状态
mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.2
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 548
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 399
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 548
              Relay_Log_Space: 554
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.02 sec)
 
ERROR:
No query specified
        注:Slave_IO_Running: Yes
            Slave_SQL_Running: Yes当IO和SQL这两个进程都是Yes,master和slave就可以进行主从复制了。
三、验证测试
 1.在master上创建一个测试表(root用户)
 mysql> use test
 mysql> create table tbs (id int);
 mysql> insert into tbs values(1);
 2.在slave上查看是否复制成功(root用户)
 mysql> use test
 mysql> show tables;
 
 mysql> select * from tbs;
                 +------+
                 | id   |
                 +------+
                 |    1 |
                 +------+
               1 row in set (0.00 sec)
显示复制成功! bitsCN.com

相关专题

更多
ip地址修改教程大全
ip地址修改教程大全

本专题整合了ip地址修改教程大全,阅读下面的文章自行寻找合适的解决教程。

86

2025.12.26

压缩文件加密教程汇总
压缩文件加密教程汇总

本专题整合了压缩文件加密教程,阅读专题下面的文章了解更多详细教程。

50

2025.12.26

wifi无ip分配
wifi无ip分配

本专题整合了wifi无ip分配相关教程,阅读专题下面的文章了解更多详细教程。

100

2025.12.26

漫蛙漫画入口网址
漫蛙漫画入口网址

本专题整合了漫蛙入口网址大全,阅读下面的文章领取更多入口。

293

2025.12.26

b站看视频入口合集
b站看视频入口合集

本专题整合了b站哔哩哔哩相关入口合集,阅读下面的文章查看更多入口。

589

2025.12.26

俄罗斯搜索引擎yandex入口汇总
俄罗斯搜索引擎yandex入口汇总

本专题整合了俄罗斯搜索引擎yandex相关入口合集,阅读下面的文章查看更多入口。

725

2025.12.26

虚拟号码教程汇总
虚拟号码教程汇总

本专题整合了虚拟号码接收验证码相关教程,阅读下面的文章了解更多详细操作。

63

2025.12.25

错误代码dns_probe_possible
错误代码dns_probe_possible

本专题整合了电脑无法打开网页显示错误代码dns_probe_possible解决方法,阅读专题下面的文章了解更多处理方案。

30

2025.12.25

网页undefined啥意思
网页undefined啥意思

本专题整合了undefined相关内容,阅读下面的文章了解更多详细内容。后续继续更新。

94

2025.12.25

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Node.js 教程
Node.js 教程

共57课时 | 7.5万人学习

ASP 教程
ASP 教程

共34课时 | 2.9万人学习

Python 教程
Python 教程

共137课时 | 6.9万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号