最新消息: 新版网站上线了!!!

mysql主从复制日志

use mysql;

update user set password=PASSWORD("1") where user='root';

flush privileges;


vi /etc/my.cnf

[mysqld]
log-bin=mysql-bin #
启动二进制文件
server-id=1 #服务器ID


#给多台从服务器授权 并关闭防火墙
grant replication slave on *.* to 'backup'@'192.168.1.101' identified by 'backup';
grant replication slave on *.* to 'backup'@'192.168.1.102' identified by 'backup';
grant replication slave on *.* to 'backup'@'192.168.1.103' identified by 'backup';

flush privileges;


 show master status;
 +------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      106 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

change master to master_host='192.168.1.101',master_user='backup',master_password='backup',master_log_file='mysql-bin.000003',master_log_pos=629;

start slave;


show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.1.101
                  Master_User: backup
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 106
               Relay_Log_File: mysqld-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             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: 106
              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 'backup@192.168.1.101:3306' - retry-time: 60  retries: 86400
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)

ERROR: 
No query specified
检查主从同步,如果您看到Slave_IO_Running和Slave_SQL_Running均为Yes,则主从复制连接正常。
Slave_SQL_Running: Yes


#/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables save

这样重启计算机后,防火墙默认已经开放了80和22端口

这里应该也可以不重启计算机:
#/etc/init.d/iptables restart

防火墙的关闭,关闭其服务即可:

查看防火墙信息:
#/etc/init.d/iptables status

关闭防火墙服务:
#/etc/init.d/iptables stop

永久关闭?不知道怎么个永久法:
#chkconfig –level 35 iptables off
.....

转载请注明:谷谷点程序 » mysql主从复制日志