mysql3308_mysql 5.7.16多源复制
演示一下在MySQL下搭建多主一從的過(guò)程。
實(shí)驗(yàn)環(huán)境:
192.168.24.129:3306
192.168.24.129:3307
192.168.24.129:3308
主庫(kù)操作
導(dǎo)出數(shù)據(jù)
分別在3306和3307上導(dǎo)出需要的數(shù)據(jù)庫(kù)。
3306:
登錄數(shù)據(jù)庫(kù):
[root@localhost 3306]# mysql -uroot -poldboy123 -S /tmp/mysql3306.sock
鎖表:
mysql> flush tables with read lock;
狀態(tài)點(diǎn):
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 |????? 154 |????????????? |????????????????? |?????????????????? |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
另開(kāi)窗口開(kāi)始導(dǎo)數(shù)據(jù):
[root@localhost tmp]# mysqldump -uroot -poldboy123 -S /tmp/mysql3306.sock -F -R -x --master-data=2 -A --events|gzip >/tmp/dockerwy.sql.gz
在此查看狀態(tài)點(diǎn)兩個(gè)要保持一致,否則表沒(méi)有鎖住
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 |????? 154 |????????????? |????????????????? |?????????????????? |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
解鎖表:
mysql> unlock tables;
3307:
登錄3307數(shù)據(jù)庫(kù):
[root@localhost 3307]# mysql -uroot -poldboy123 -S /tmp/mysql3307.sock
鎖表:
mysql>flush tables with read lock;
查看狀態(tài)點(diǎn):
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 |????? 154 |????????????? |????????????????|?????????????????? |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
另開(kāi)窗口導(dǎo)數(shù)據(jù):
[root@localhost 3307]# mysqldump -uroot -poldboy123 -S /tmp/mysql3307.sock -F -R -x --master-data=2 -A --events|gzip >/tmp/dockerwy_2.sql.gz
從新查看狀態(tài)點(diǎn):
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000008 |????? 154 |????????????? |????????????????? |?????????????????? |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
解鎖表:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
建立授權(quán)賬號(hào)
分別在3306和3307上面建立授權(quán)賬號(hào)
3306:
mysql> grant replication slave on *.* to 'backup'@'192.168.24.129' identified by 'backup';
3307:
mysql> grant replication slave on *.* to 'backup'@'192.168.24.129' identified by 'backup';
從庫(kù)操作
修改從庫(kù)存儲(chǔ)方式
修改3308的master-info和relay-info方式,從文件存儲(chǔ)改為表存儲(chǔ)。
編輯配置文件
[root@localhost 3308]# vim my.cnf
在[mysqld]模塊下添加如下兩行
master_info_repository=TABLE
relay_log_info_repository=TABLE
重啟3308數(shù)據(jù)庫(kù):
[root@localhost 3308]# /data/3308/mysqld restart
重啟之后我們可以登錄數(shù)據(jù)庫(kù)查看;
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'relay_log_info_repository';
+---------------------------+-------+
| Variable_name???????????? | Value |
+---------------------------+-------+
| relay_log_info_repository | TABLE |
+---------------------------+-------+
1 row in set (0.01 sec)
mysql> show variables like 'master_info_repository';
+------------------------+-------+
| Variable_name????????? | Value |
+------------------------+-------+
| master_info_repository | TABLE |
+------------------------+-------+
1 row in set (0.01 sec)
導(dǎo)入數(shù)據(jù)
導(dǎo)入3306的數(shù)據(jù):
[root@localhost 3308]# gzip -d /tmp/dockerwy.sql.gz
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock < /tmp/dockerwy.sql.
導(dǎo)入3307的數(shù)據(jù):
[root@localhost 3308]# gzip -d /tmp/dockerwy_2.sql.gz
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock < /tmp/dockerwy_2.sql
執(zhí)行change master to
登錄slave進(jìn)行同步操作,分別change master兩臺(tái)服務(wù)器,后面以for channel ‘channel_name’區(qū)分
mysql> change master to master_host='192.168.24.129',master_user='backup',master_port=3306,master_password='backup',master_log_file='mysql-bin.000006',master_log_pos=154 for channel 'master_1';
Query OK, 0 rows affected, 2 warnings (0.07 sec)
mysql> change master to master_host='192.168.24.129',master_user='backup',master_port=3307,master_password='backup',master_log_file='mysql-bin.000007',master_log_pos=154 for channel 'master_2';
Query OK, 0 rows affected, 2 warnings (0.04 sec)
啟動(dòng)slave操作
可以通過(guò)start slave的方式去啟動(dòng)所有的復(fù)制,也可以通過(guò)單個(gè)復(fù)制源的方式,下面介紹單個(gè)復(fù)制的的啟動(dòng)演示
mysql> start slave for channel 'master_1';
Query OK, 0 rows affected (0.01 sec)
mysql> start slave for channel 'master_2';
Query OK, 0 rows affected (0.02 sec)
查看同步狀態(tài)
正常啟動(dòng)后,可以查看同步的狀態(tài),執(zhí)行show slave status for channel ‘channel_name\G’查看復(fù)制源master_1的同步狀態(tài);
mysql> show slave status for channel 'master_1'\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.24.129
Master_User: backup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin-master_1.000006
Relay_Log_Pos: 367
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: 154
Relay_Log_Space: 634
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: 129
Master_UUID: df233252-afd5-11e6-8070-000c2962d708
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:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master_1
Master_TLS_Version:
1 row in set (0.00 sec)
查看master_2的同步狀態(tài)
mysql> mysql> show slave status for channel 'master_2'\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.24.129
Master_User: backup
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin-master_2.000004
Relay_Log_Pos: 367
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: 154
Relay_Log_Space: 634
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: 130
Master_UUID: 49bf20e1-afe2-11e6-aef5-000c2962d708
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:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: master_2
Master_TLS_Version:
1 row in set (0.00 sec)
總結(jié)
以上是生活随笔為你收集整理的mysql3308_mysql 5.7.16多源复制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 怎么卸载深度装机大师 如何完全删除深度装
- 下一篇: u盘卡顿厉害怎么解决 解决U盘卡顿问题的