ITPub博客

首页 > 数据库 > MySQL > MYSQL主从复制

MYSQL主从复制

原创 MySQL 作者:oraclesuperman 时间:2015-07-31 10:31:33 0 删除 编辑

主库:

[root@dba ~]# cat /etc/my.cnf
[mysqld]
server_id=77
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#skip-grant-tables
character_set_server=utf8
#autocommit=off
log-bin=/var/lib/mysql/feige-bin
#binlog_format=STATEMENT
#binlog_format=MIXED
binlog_format=ROW


mysql> grant replication slave on *.* to 'feige'@'196.128.1.78' identified by 'feige';
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| feige-bin.000014 |      619 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)


[root@dba ~]# mysqldump -uroot -p  --all-databases > /tmp/mysql.sql
Enter password:


[root@dba ~]# scp  /tmp/mysql.sql  root@196.128.1.78:/tmp
The authenticity of host '196.128.1.78 (196.128.1.78)' can't be established.
RSA key fingerprint is cc:19:02:09:23:b8:5c:95:32:f1:66:a1:7d:c6:a1:82.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '196.128.1.78' (RSA) to the list of known hosts.
root@196.128.1.78's password:
mysql.sql                                                                                                  100% 1111KB   1.1MB/s   00:00



从库:

[root@dba ~]# cat /etc/my.cnf
[mysqld]
server_id=78
datadir = "/var/lib/mysql"


[root@dba ~]#  mysql -uroot  -p < /tmp/mysql.sql
Enter password:


mysql> change master to
    -> master_host='196.128.1.77',
    -> master_user='feige',
    -> master_password='feige',
    -> master_port=3306,
    -> master_log_file='feige-bin.000014',
    -> master_log_pos=619;
Query OK, 0 rows affected, 2 warnings (0.07 sec)

mysql>  start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 196.128.1.77
                  Master_User: feige
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: feige-bin.000014
          Read_Master_Log_Pos: 817
               Relay_Log_File: dba-relay-bin.000002
                Relay_Log_Pos: 481
        Relay_Master_Log_File: feige-bin.000014
             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: 817
              Relay_Log_Space: 652
              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:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 77
                  Master_UUID: 653a1416-29d4-11e5-9e4a-080027f0245d
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified


主库:
mysql> drop table t;
Query OK, 0 rows affected (0.07 sec)

从库:

mysql> select * from t;
ERROR 1146 (42S02): Table 'test.t' doesn't exist


mysql> show processlist \G;
*************************** 1. row ***************************
     Id: 17
   User: root
   Host: localhost
     db: test
Command: Query
   Time: 0
  State: init
   Info: show processlist
*************************** 2. row ***************************
     Id: 107
   User: feige
   Host: 196.128.1.78:52367
     db: NULL
Command: Binlog Dump
   Time: 1495
  State: Master has sent all binlog to slave; waiting for binlog to be updated
   Info: NULL
2 rows in set (0.00 sec)

ERROR:
No query specified



mysql> show processlist \G;
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost
     db: test
Command: Query
   Time: 0
  State: init
   Info: show processlist
*************************** 2. row ***************************
     Id: 3
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 1574
  State: Waiting for master to send event
   Info: NULL
*************************** 3. row ***************************
     Id: 4
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 1475
  State: Slave has read all relay log; waiting for the slave I/O thread to update it
   Info: NULL
3 rows in set (0.00 sec)

ERROR:
No query specified

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29313086/viewspace-1757444/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Mysql热备份
请登录后发表评论 登录
全部评论

注册时间:2015-03-20

  • 博文量
    178
  • 访问量
    399004