加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MYSQL使用心得(二) 主从复制

发布时间:2016-08-10 01:14:47 所属栏目:MySql教程 来源:站长网
导读:基本配置 主数据库 配置文件,修改server_id=1 建立账户,供slave同步使用 GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.56.3' identified by 'repl'; M
基本配置

主数据库

配置文件,修改server_id=1

建立账户,供slave同步使用

GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.56.3' identified by 'repl';

Mysql> show master status;

+------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000005 | 261 | | |

+------------------+----------+--------------+------------------+

记录下 FILE 及 Position 的值,在后面进行从服务器操作的时候需要用到。

从数据库

配置文件,修改server_id=2

执行同步SQL语句,地址为主数据库地址,和主数据库上的用户名和密码

change master to

master_host='192.168.56.2',

master_user='repl',

master_password='repl',

master_log_file='mysql-bin.000005',

master_log_pos=261;

正确执行后启动Slave同步进程

start slave;

主从同步检查

mysql> show slave statusG

==============================================

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

              Slave_IO_State: Waiting for master to send event

                 Master_Host: 192.168.56.2

                 Master_User: test

                 Master_Port: 3306

               Connect_Retry: 60

             Master_Log_File: mysql-bin.000008

         Read_Master_Log_Pos: 258

              Relay_Log_File: Slave2-relay-bin.000003

               Relay_Log_Pos: 404

       Relay_Master_Log_File: mysql-bin.000008

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

             Relay_Log_Space: 561

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

==============================================

其中Slave_IO_Running 与 Slave_SQL_Running 的值都必须为YES,才表明状态正常。

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读