MySQL 主从复制(Ubuntu+宝塔)

世界可以没有日本,不能没有海洋。

1)主服务器master配置文件修改

vim /etc/my.cnf

修改或者添加log-bin和server-id

[mysqld]
log-bin=mysql-bin   
server-id=1      //唯一性

2)从服务器slave配置文件修改

vim /etc/my.cnf

修改或者添加log-bin和server-id

[mysqld]
log-bin=mysql-bin   
server-id=2     //唯一性

3)主服务器添加远程连接账号

GRANT REPLICATION SLAVE ON *数据库* to '账号'@'%' identified by '密码'; 

4)登录主服务器查看master状态

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.0000001|   100000 | wp           |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

记住File字段的mysql-bin.0000001,Position的100000

5)配置从服务器slave

CHANGE MASTER TO MASTER_HOST='主服务器IP',
MASTER_PORT=主服务器MySQL端口,
MASTER_USER='远程连接的账号',
MASTER_PASSWORD='远程连接的密码',

MASTER_LOG_FILE='mysql-bin.0000001',

MASTER_LOG_POS=100000;

开启salve

  Mysql>start slave;

6)查询从服务器的状态

mysql> show slave statusG
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 主服务器IP
                  Master_User: 远程连接的账号
                  Master_Port: 主服务器MySQL端口
                Connect_Retry: 60
              Master_Log_File: mysql-bin.0000001
          Read_Master_Log_Pos: 100000
               Relay_Log_File: 不让你看-relay-bin.000002
                Relay_Log_Pos: 001
        Relay_Master_Log_File: mysql-bin.0000001
             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: 100000
              Relay_Log_Space: 001
              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: 111
1 row in set (0.00 sec)

查看Slave_IO_Running和Slave_SQL_Running状态是否都是Yes.

都是YES则配置成功

否则失败

主主备份就是主从备份反向操作

也适用于宝塔的MySQL数据库设置主从备份

7)测试

在主服务器的MySQL修改字段的值,然后查看从服务器MySQL的值



知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

生成海报
点赞 0

暂无评论

相关推荐

目录展开