• day6-主从


    主从同步

    公共配置

    运行数据库服务

    从数据库服务器上一定有主数据库服务器上的库和表,且表结构要一致

    关闭iptables禁用selinux

    配置

    主机A192.168.100.100为主mysql

    1. 必须启用binlog日志
    • 指定server-id

      [root@localhost ~]# head -3 /etc/my.cnf

      [mysqld]

      log-bin

      server_id=100

    1. 授权一个连接用户可以从B主机来连接自己,连接自己后有拷贝数据的权限

      mysql> grant replication slave on *.* to admin@"192.168.100.101" identified by "1";

    配置B主机192.168.100.101做从数据库服务器

    1. 测试授权用户是否有效
    2. 在自己本机使用自己的数据库管理员登陆,设置自己做192.168.100.100的从数据库服务器

      [root@localhost ~]# head -3 /etc/my.cnf

      [mysqld]

      log-bin

      server_id=101

    连接主服务器上查看

    mysql> change master to master_host="192.168.100.100",master_user='admin',master_password="1",master_log_file="mysqld-bin.000001",master_log_pos=394;

    mysql> show slave statusG;

    *************************** 1. row ***************************

    Slave_IO_State:

    Master_Host: 192.168.100.100

    Master_User: admin

    Master_Port: 3306

    Connect_Retry: 60

    Master_Log_File: mysqld-bin.000001

    Read_Master_Log_Pos: 394

    Relay_Log_File: mysqld-relay-bin.000001

    Relay_Log_Pos: 4

    Relay_Master_Log_File: mysqld-bin.000001

    Slave_IO_Running: No

    Slave_SQL_Running: No

    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: 394

    Relay_Log_Space: 106

    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: NULL

    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.00 sec)

    ERROR:

    No query specified

    mysql> start slave;

    mysql> show slave statusG;

    *************************** 1. row ***************************

    Slave_IO_State: Waiting for master to send event

    Master_Host: 192.168.100.100

    Master_User: admin

    Master_Port: 3306

    Connect_Retry: 60

    Master_Log_File: mysqld-bin.000001

    Read_Master_Log_Pos: 394

    Relay_Log_File: mysqld-relay-bin.000002

    Relay_Log_Pos: 252

    Relay_Master_Log_File: mysqld-bin.000001

    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: 394

    Relay_Log_Space: 408

    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.00 sec)

    ERROR:

    No query specified

    验证——在任何主修改数据都会同步。

    IO进程:负责拷贝主数据库服务器binlog日志里的sql语句到本机的中继binlog日志里

    IO进程什么时候会出错——连接不上主数据库服务器时会出错

        网络、授权

    SQL进程:负责执行本机中继binlog日志里sql语句把数据写进数据库

    SQL进程什么时候会出错——SQL语句操作的库、表、字段在自己本机不存在 

    Slave_IO_Running: Yes    IO进程

    Slave_SQL_Running: Yes  SQL进程

    IO进程报错信息

    Last_IO_Errno: 0    报错个数

    Last_IO_Error:      报错具体信息

    SQL进程报错信息

    Last_SQL_Errno: 0

    Last_SQL_Error

    mysql>stop slave;

    mysql>change master to 选项=值;

    mysql>start slave;

    mysql>

       

    master.info    记录主数据库服务器的信息

    name-relay-bin.00000x  中继binlog日志

    name-relay-bin.index  记录已有的中继binlog日志

    relay-log.info    记录中继日志信息

    mysql主从同步的结构模式

    一主一从  A主机为主,B主机为从

    一主多从  A主机为主,B主机为从,C主机为从

    主从从   A主机为主,B主机为从,但是C主机的人,C主机为从,B是他的主

          B主机配置文件需加  log-slave-update  默认从的SQL记录不会记录到本机

    主主结构(互为主从)

       A主机是B的从,也是他的主。B主机同理

    控制主从同步时,只备份指定的数据库而不是备份所有库

    授权是无法实现的,会报错

    两种方法

    1、在主数据库服务器端控制

    vim /etc/my.cnf

    【mysqld】

    binlog-do-db=db_name    允许同步这个库

    或binlog-ignore-db=db_name    只不同步这个库

    2、在从数据库服务器控制

    vim /etc/my.cnf

    【mysqld】

    replicate-do-db=db_name    只备份这个库

    replicate-ignore-db=db_name    只不备份这个库

  • 相关阅读:
    An impassioned circulation of affection(尺取+预处理)
    旅游(CSUST省赛选拔赛2+状压dp+最短路)
    Islands and Bridges(POJ2288+状压dp+Hamilton 回路)
    Travelling(HDU3001+状压dp+三进制+最短路)
    Hie with the Pie(POJ3311+floyd+状压dp+TSP问题dp解法)
    hash(2018年CSUST省赛选拔赛第一场B题+hash+字典树)
    Everything Has Changed(HDU6354+圆交+求周长)
    [iOS Animation]-CALayer 图层几何学
    [iOS Animation]-CALayer 显示方式
    [iOS Animation]-CALayer 图层树
  • 原文地址:https://www.cnblogs.com/fina/p/5849890.html
Copyright © 2020-2023  润新知