首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    学习笔记0601----mysql主从

    Mysql的 Replication 是一个异步的复制过程,从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql instance(我们称之 Slave)。在 Master 与 Slave 之间的实现整个复制过程主要由三个线程来完成,其中两个线程(Sql线程和IO线程)在 Slave 端,另外一个线程(IO线程)在 Master 端。   要实现 MySQL 的 Replication ,首先必须打开 Master 端的Binary Log(mysql-bin.xxxxxx)功能,否则无法实现。因为整个复制过程实际上就是Slave从Master端获取该日志然后再在自己身上完全 顺序的执行日志中所记录的各种操作。打开 MySQL 的 Binary Log 可以通过在启动 MySQL Server 的过程中使用 “—log-bin” 参数选项,或者在 my.cnf 配置文件中的 mysqld 参数组([mysqld]标识后的参数部分)增加 “log-bin” 参数项。

    02

    MYSQL 的 MASTER到MASTER的主主循环同步

    刚刚抽空做了一下MYSQL 的主主同步。 把步骤写下来,至于会出现的什么问题,以后随时更新。这里我同步的数据库是TEST 1、环境描述。    主机:192.168.0.231(A)    主机:192.168.0.232(B)    MYSQL 版本为5.1.21 2、授权用户。 A: mysql> grant replication slave,file on *.* to 'repl1'@'192.168.0.232' identified  by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) B: mysql> grant replication slave,file on *.* to 'repl2'@'192.168.0.231' identified  by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 然后都停止MYSQL 服务器。 3、配置文件。 在两个机器上的my.cnf里面都开启二进制日志 。 A: user = mysql log-bin=mysql-bin server-id       = 1 binlog-do-db=test binlog-ignore-db=mysql replicate-do-db=test replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=1 B: user = mysql log-bin=mysql-bin server-id       = 2 binlog-do-db=test binlog-ignore-db=mysql replicate-do-db=test replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=2 至于这些参数的说明具体看手册。 红色的部分非常重要,如果一个MASTER 挂掉的话,另外一个马上接管。 紫红色的部分指的是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。 4、重新启动MYSQL服务器。 在A和B上执行相同的步骤 [root@localhost ~]# /usr/local/mysql/bin/mysqld_safe & [1] 4264 [root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'. /usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected 071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data 5、进入MYSQL的SHELL。 A: mysql> flush tables with read lock\G Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row ***************************             File: mysql-bin.000007         Position: 528     Binlog_Do_DB: test Binlog_Ignore_DB: mysql 1 row in set (0.00 sec) B: mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status\G *************************** 1. row **************************

    02

    MySQL 的一次错误处理 Got fatal error 1236 from master when reading data from binary log

    mysql 5.5.28-log> show slave status\G *************************** 1. row ***************************                Slave_IO_State:                    Master_Host: 88.88.88.88                   Master_User: replicate                   Master_Port: 3306                 Connect_Retry: 60               Master_Log_File: testdbbinlog.000005           Read_Master_Log_Pos: 98359687                Relay_Log_File: mysql-relay-bin.000020                 Relay_Log_Pos: 4         Relay_Master_Log_File: testdbbinlog.000005              Slave_IO_Running: No             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: 98359687               Relay_Log_Space: 107               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: 1236                 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'                Last_SQL_Errno: 0                Last_SQL_Error:    Replicate_Ignore_Server_Ids:               Master_Server_Id: 1 1 row in set (0.00 sec)

    02
    领券