2013年11月17日星期日

mysql 主从同步,双主同步,如果服务器意外挂机,不同步怎么办

本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订
mysql 主从同步,双主同步,如果服务器意外挂机,不同步怎么办  阅读原文»

mysql 主从同步,双主同步,如果服务器意外挂机,不同步怎么办

mysql 主从同步,双主同步,如果服务器意外挂机,不同步怎么办

首先主从同步

master 192.168.0.21

slave 192.168.0.22

  #my.cnf master 配置文件  [client]  port            = 3306  socket          = /tmp/mysql.sock  default-character-set=utf8  [mysqld]  port            = 3306  socket          = /tmp/mysql.sock  skip-external-locking  key_buffer_size = 16M  max_allowed_packet = 1M  table_open_cache = 64  sort_buffer_size = 512K  net_buffer_length = 8K  default-character-set=utf8  read_buffer_size = 256K  read_rnd_buffer_size = 512K  myisam_sort_buffer_size = 8M  log-bin=mysql-bin  binlog_format=mixed  [mysqldump]  quick  max_allowed_packet = 16M  [mysql]  no-auto-rehash  default-character-set=utf8  [myisamchk]  key_buffer_size = 20M  sort_buffer_size = 20M  read_buffer = 2M  write_buffer = 2M  [mysqlhotcopy]  interactive-timeout  server-id= 1  #增加3条配置  binlog-do-db=abc  #设置同步数据库,如果有多个数据库,每个数据库一行  binlog-ignore-db = mysql #设置不要同步的数据库,如有多个数据库,每个数据库一行  log-bin #日志文件  

service mysql restart #重启数据库

  进入mysql,创建一个数据库abc:  create database abc;  创建一个用来同步的用户,指定只能在192.168.0.22登录:  grant replication slave on *.* to 'root'@'192.168.0.22'identified by '123456';  mysql> use abc  Database changed  mysql> create table bb(idint, name varchar(20),age int);  Query OK, 0 rows affected (0.05 sec)  #注意表和数据库格式必须一样  
  #slave  mysql>  create database abc;  Query OK, 1 row affected (0.00 sec)  mysql> use abc  Database changed  mysql> create table bb(idint, name varchar(20),age int);  Query OK, 0 rows affected (0.01 sec)  
  #slave  #my.cnf 配置  [client]  port            = 3306  socket          = /tmp/mysql.sock  default-character-set=utf8  [mysqld]  port            = 3306  socket          = /tmp/mysql.sock  skip-external-locking  key_buffer_size = 16M  max_allowed_packet = 1M  table_open_cache = 64  sort_buffer_size = 512K  net_buffer_length = 8K  default-character-set=utf8  read_buffer_size = 256K  read_rnd_buffer_size = 512K  myisam_sort_buffer_size = 8M  log-bin=mysql-bin  binlog_format=mixed  server-id= 2   #id  master-host=192.168.0.21  #mysql主ip地址  master-user=root   #授权用户  master-password=123456  #授权密码  master-port=3306    #mysql端口  master-connect-retry=30   #同步  replicate-ignore-db=mysql   #设置不要接收的数据库,如有多个数据库,每个数据库一行  replicate-do-db=abc  #设置要接收的数据库,如有多个数据库,每个数据库一行  log-bin  [mysqldump]  quick  max_allowed_packet = 16M  [mysql]  no-auto-rehash  default-character-set=utf8  [myisamchk]  key_buffer_size = 20M  sort_buffer_size = 20M  read_buffer = 2M  write_buffer = 2M  [mysqlhotcopy]  interactive-timeout  ~  
  #主上查看  mysql> show master status;  +------------------+----------+--------------+------------------+  | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |  +------------------+----------+--------------+------------------+  | mysql-bin.000025 |      377 | abc          |                  |  +------------------+----------+--------------+------------------+  1 row inset(0.00 sec)  # 记录下file和position的值  #slave 上  CHANGE MASTER TO MASTER_LOG_FILE=' mysql-bin.000025',MASTER_LOG_POS=377;  # 根据master状态同步  mysql> slave start;  # 启动slave  mysql> show slave status\G;  

发现报错信息

  mysql> show slave status\G;  *************************** 1. row ***************************  Slave_IO_State: Connecting to master  Master_Host: 192.168.0.21  Master_User: root  Master_Port: 3306  Connect_Retry: 60  Master_Log_File:  mysql-bin.000025  Read_Master_Log_Pos: 377  Relay_Log_File: localhost-relay-bin.000001  Relay_Log_Pos: 4  Relay_Master_Log_File:  mysql-bin.000025  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: 377  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: 2013  Last_IO_Error: error connecting to master 'root@192.168.0.21:330                                                                                                                                                             6'- retry-time: 60  retries: 86400  Last_SQL_Errno: 0  Last_SQL_Error:  1 row inset(0.00 sec)  ERROR:  No query specified  
  或者vi/etc/sysconfig/iptables  -I INPUT -p tcp --dport 3360 -j DROP  -I INPUT -s 119.134.251.49/32-p tcp --dport 3306 -j ACCEPT  前面那个问题可能是防火墙问题,这次这个问题,是我以前以前同步过现在在做同步就报错了,给出解决方案。  [root@localhost ~]# service iptables stop  iptables:清除防火墙规则:                                 [确定]  iptables:将链设置为政策 ACCEPT:filter                    [确定]  iptables:正在卸载模块:                                   [确定]  [root@localhost ~]# mysql -uroot -p123456  Welcome to the MySQL monitor.  Commands end with ; or \g.  Your MySQL connection idis 7  Server version: 5.1.60-log Source distribution  Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.  Oracle is a registered trademark of Oracle Corporation and/orits  affiliates. Other names may be trademarks of their respective  owners.  Type 'help;'or '\h'forhelp. Type '\c'to clearthe current input statement.  mysql> slave stop;  Query OK, 0 rows affected (0.00 sec)  mysql> CHANGE MASTER TO MASTER_LOG_FILE=' mysql-bin.000025',MASTER_LOG_POS=377;  Query OK, 0 rows affected (0.05 sec)  mysql> slave start;  Query OK, 0 rows affected (0.00 sec)  mysql> show slave status\G;  *************************** 1. row ***************************  Slave_IO_State:  Master_Host: 192.168.0.21  Master_User: root  Master_Port: 3306  Connect_Retry: 60  Master_Log_File:  mysql-bin.000025  Read_Master_Log_Pos: 377  Relay_Log_File: localhost-relay-bin.000001  Relay_Log_Pos: 4  Relay_Master_Log_File:  mysql-bin.000025  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: 377  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: 1236  Last_IO_Error: Got fatal error 1236 from master when reading da

阅读更多内容

没有评论:

发表评论