Linux Mysql 主从复制
Posted 记录每天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux Mysql 主从复制相关的知识,希望对你有一定的参考价值。
# 三台主机: # 主节点:10.0.0.21 # 从节点1:10.0.0.22,从节点2:10.0.0.23 # 主节点配置 [21:46:32 root@centos7 ~]#cat /etc/my.cnf [mysqld] server-id=21 log-bin datadir=/data/mysql skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock [mysql] prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_" # 在mysql里面配置丛节点复制的账户 :31: (root@localhost) [(none)]> create user repluser@\'10.0.0.%\' identified by \'replpass\'; Query OK, 0 rows affected (0.00 sec) :33: (root@localhost) [(none)]> grant replication slave on *.* to repluser@\'10.0.0.%\'; Query OK, 0 rows affected (0.00 sec) # 记录当前binlog的地址 :43: (root@localhost) [(none)]> show master logs; +--------------------+-----------+ | Log_name | File_size | +--------------------+-----------+ | centos7-bin.000001 | 177 | | centos7-bin.000002 | 20780 | +--------------------+-----------+ # 从节点设置 # 首先配置my.cnf [21:50:27 root@centos7 ~]#cat /etc/my.cnf [mysqld] server-id=22 datadir=/data/mysql skip_name_resolve=1 log-bin socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid read-only=on relay-log=relay-log relay-log-index=relay-log.index [client] socket=/data/mysql/mysql.sock [mysql] prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_" # 在mysql里面配置主节点信息 :44: (root@localhost) [(none)]> CHANGE MASTER TO -> MASTER_HOST=\'10.0.0.21\', -> MASTER_USER=\'repluser\', -> MASTER_PASSWORD=\'replpass\', -> MASTER_PORT=3306, -> MASTER_LOG_FILE=\'centos7-bin.000002\', -> MASTER_LOG_POS= 20780; Query OK, 0 rows affected, 2 warnings (0.00 sec) :44: (root@localhost) [(none)]> start slave; # 若配置错误,请stop slave, 然后再reset slave,最后再重新配置CHANGE MASTER TO # 查看是否成功 :44: (root@localhost) [(none)]> show slave status\\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.0.21 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: centos7-bin.000002 Read_Master_Log_Pos: 20780 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 322 Relay_Master_Log_File: centos7-bin.000002 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: 20780 Relay_Log_Space: 523 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: 21 Master_UUID: 779fe189-d421-11eb-83d6-000c299f2dc7 Master_Info_File: /data/mysql/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: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)
以上是关于Linux Mysql 主从复制的主要内容,如果未能解决你的问题,请参考以下文章