mysql容器之间的replication配置实例详解


当前第2页 返回上一页

配置mysql_master

mysql> change master to master_host='192.168.1.139',master_user='slave',master_password='slave',master_log_file='slave-log.000001',master_port=3307, master_log_pos=1460;
Query OK, 0 rows affected, 2 warnings (1.17 sec)

mysql> change master to master_host='192.168.1.139',master_user='slave',master_password='slave',master_auto_position=1,get_master_public_key=1;
Query OK, 0 rows affected, 2 warnings (0.45 sec)

配置mysql_slave

mysql> change master to master_host='192.168.1.108',master_user='slave',master_password='slave',master_log_file='master-log.000001',master_port=3307, master_log_pos=156;
Query OK, 0 rows affected, 2 warnings (0.15 sec)

mysql> change master to master_host='192.168.1.108',master_user='slave',master_password='slave',master_auto_position=1,get_master_public_key=1;
Query OK, 0 rows affected, 2 warnings (0.14 sec)

开启复制

mysql_master上start slave
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

查看slave status,发现并没有成功启动复制。出现错误 Access denied for user 'slave'@'172.17.0.1' (using password: YES) 需要到mysql_slave上创建响应的用户和权限,

mysql> show slave status \G;
*************************** 1. row ***************************
  Slave_IO_State: Connecting to master
   Master_Host: 192.168.1.139
   Master_User: slave
   Master_Port: 3307
  Connect_Retry: 60
  Master_Log_File:
  Read_Master_Log_Pos: 4
  Relay_Log_File: relay-log.000001
  Relay_Log_Pos: 4
 Relay_Master_Log_File:
  Slave_IO_Running: Connecting
  Slave_SQL_Running: Yes
  Replicate_Do_DB:
  Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
  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: 0
  Relay_Log_Space: 156
  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: 1045
  Last_IO_Error: error connecting to master 'slave@192.168.1.139:3307' - retry-time: 60 retries: 2 message: Access denied for user 'slave'@'172.17.0.1' (using password: YES)
  Last_SQL_Errno: 0
  Last_SQL_Error:
 Replicate_Ignore_Server_Ids:
  Master_Server_Id: 0
   Master_UUID:
  Master_Info_File: mysql.slave_master_info
   SQL_Delay: 0
  SQL_Remaining_Delay: NULL
 Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  Master_Retry_Count: 86400
   Master_Bind:
 Last_IO_Error_Timestamp: 210110 13:02:12
 Last_SQL_Error_Timestamp:
  Master_SSL_Crl:
  Master_SSL_Crlpath:
  Retrieved_Gtid_Set:
  Executed_Gtid_Set:
  Auto_Position: 1
  Replicate_Rewrite_DB:
   Channel_Name:
  Master_TLS_Version:
 Master_public_key_path:
 Get_master_public_key: 1
  Network_Namespace:
1 row in set (0.01 sec)

ERROR:
No query specified

mysql> exit

mysql_slave 启动slave并查看slave status发现一切正常

mysql> show slave status;
mysql> show slave status\G;
*************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
   Master_Host: 192.168.1.108
   Master_User: slave
   Master_Port: 3307
  Connect_Retry: 60
  Master_Log_File: master-log.000001
  Read_Master_Log_Pos: 156
  Relay_Log_File: relay-log.000002
  Relay_Log_Pos: 373
 Relay_Master_Log_File: master-log.000001
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB:
  Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
  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: 156
  Relay_Log_Space: 576
  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
   Master_UUID: 9627309d-5341-11eb-aaa3-0242ac110006
  Master_Info_File: mysql.slave_master_info
   SQL_Delay: 0
  SQL_Remaining_Delay: NULL
 Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  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: f102ae13-5341-11eb-a578-0242ac110002:1-5
  Auto_Position: 1
  Replicate_Rewrite_DB:
   Channel_Name:
  Master_TLS_Version:
 Master_public_key_path:
 Get_master_public_key: 1
  Network_Namespace:
1 row in set, 1 warning (0.01 sec)

ERROR:
No query specified

mysql_slave 上创建用户

mysql> CREATE USER 'slave'@'172.17.0.1' IDENTIFIED BY 'slave';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'172.17.0.1';
Query OK, 0 rows affected (0.00 sec)

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

再次查看mysql_master上的slave status,一切正常

mysql> show slave status \G;
*************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
   Master_Host: 192.168.1.139
   Master_User: slave
   Master_Port: 3307
  Connect_Retry: 60
  Master_Log_File: slave-log.000001
  Read_Master_Log_Pos: 2022
  Relay_Log_File: relay-log.000002
  Relay_Log_Pos: 2237
 Relay_Master_Log_File: slave-log.000001
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB:
  Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
  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: 2022
  Relay_Log_Space: 2440
  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: 2
   Master_UUID: f102ae13-5341-11eb-a578-0242ac110002
  Master_Info_File: mysql.slave_master_info
   SQL_Delay: 0
  SQL_Remaining_Delay: NULL
 Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  Master_Retry_Count: 86400
   Master_Bind:
 Last_IO_Error_Timestamp:
 Last_SQL_Error_Timestamp:
  Master_SSL_Crl:
  Master_SSL_Crlpath:
  Retrieved_Gtid_Set: f102ae13-5341-11eb-a578-0242ac110002:1-7
  Executed_Gtid_Set: f102ae13-5341-11eb-a578-0242ac110002:1-7
  Auto_Position: 1
  Replicate_Rewrite_DB:
   Channel_Name:
  Master_TLS_Version:
 Master_public_key_path:
 Get_master_public_key: 1
  Network_Namespace:
1 row in set (0.01 sec)

ERROR:
No query specified

测试复制
mysql_slave上创建test_db_slave

mysql> CREATE DATABASE test_db_slave;
Query OK, 1 row affected (0.01 sec)

mysql_master上创建test_db_master

mysql> CREATE DATABASE test_db_master;
Query OK, 1 row affected (0.24 sec)

查看mysql_slave上的databases

mysql> show databases;
+--------------------+
| Database  |
+--------------------+
| information_schema |
| mysql  |
| performance_schema |
| sys  |
| test_db_master |
| test_db_slave |
+--------------------+
6 rows in set (0.00 sec)

mysql>

查看mysql_master上的databases

mysql> show databases;
+--------------------+
| Database  |
+--------------------+
| information_schema |
| mysql  |
| performance_schema |
| sys  |
| test_db_master |
| test_db_slave |
+--------------------+
6 rows in set (0.00 sec)

mysql>

至此,mysql replication配置完毕。

到此这篇关于mysql容器之间的replication配置的文章就介绍到这了,更多相关mysql容器的replication配置内容请搜索

更多Mysql内容来自木庄网络博客


标签:Mysql

返回前面的内容

相关阅读 >>

mysql怎么卸载干净?

mysql 常用函数总结

mysql乐观锁是什么?

mysql 字符串拆分操作(含分隔符的字符串截取)

mysql如何创建和删除索引?

mysql 存储过程中使用动态sql语句

mysql悲观锁怎么实现?

mysql 的replace into详解

mysql数据库锁定机制详细介绍

mysql怎样查看帮助

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...