如何基於生產環境mysql 5.6.25主從部署新的mysql從庫操作指南
1,背景需求
由於現網的環境,經過近期監控,發現MYSQL主庫的IO讀寫壓力比較大,需要部署新的MYSQL從庫,進一步分攤MYSQL主庫的壓力,以及現存MYSQL從庫的讀負載。為了減少對於MYSQL主庫的IO讀取效能衝擊,採用基於MYSQL現存從庫構建新的MYSQL從庫。
2,現存的資料庫架構
編號 IP地址 資料庫角色
1 10.0.0.12 資料庫主庫
2 10.0.0.16 資料庫從庫1
3,準備好一個新的資料庫從庫2
編號 IP地址 資料庫角色
3 10.0.0.14 資料庫從庫2
4,在新的資料庫從庫2,配置server_id=3,區別於上述2個節點
5,在資料庫從庫1,關閉sql thread,為了實現MYSQLDUMP備份的資料一致性;
mysql> system hostname
standby3
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
6,在資料庫從庫1,獲取show slave status之如下標註的2個列
(注:用於基於這個列的值,用於後續構建新的MYSQL從庫)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.0.0.12
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000002
Read_Master_Log_Pos: 120
Relay_Log_File: standby3-relay-bin.000004
Relay_Log_Pos: 280
Relay_Master_Log_File: binlog.000002 ---應用主庫二進位制日誌
Slave_IO_Running: No
Slave_SQL_Running: No
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: 120 ---應用主庫二進位制日誌的位置
Relay_Log_Space: 500
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: NULL
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: 65fddb9f-fd33-11e9-95f0-080027d1f3fc
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
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
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
7,在MYSQL從庫1匯出資料庫備份
[root@standby3 mysql]# mysqldump -uroot -psystem --databases zxydb >/dump_dir/for_create_2_slave.dump
Warning: Using a password on the command line interface can be insecure.
[root@standby3 mysql]#
8,重啟MYSQL從庫1的SQL THREAD
mysql> start slave sql_thread;
Query OK, 0 rows affected (0.01 sec)
9,把MYSQL從庫1 複製資料庫份到 MYSQL從庫2
[root@standby2mysql mysql]# mkdir -p /dump_dir
[root@standby2mysql mysql]#
[root@standby3 mysql]# scp /dump_dir/for_create_2_slave.dump root@10.0.0.14:/dump_dir/
root@10.0.0.14's password:
for_create_2_slave.dump 100% 2530 2.5KB/s 00:00
[root@standby3 mysql]#
10,在MYSQL從庫2匯入DUMP檔案
[root@standby2mysql mysql]# mysql -uroot -psystem </dump_dir/for_create_2_slave.dump
Warning: Using a password on the command line interface can be insecure.
[root@standby2mysql mysql]#
[root@standby2mysql mysql]# mysql -uroot -psystem
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.6.25-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zxydb |
+--------------------+
5 rows in set (0.00 sec)
11,在MYSQL主庫建立用於構建MYSQL從庫2連線MYSQL主庫的複製資料庫使用者
mysql> create user 'repl'@'10.0.0.14' identified by 'system';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'10.0.0.14';
Query OK, 0 rows affected (0.00 sec)
12,在MYSQL從庫2構建至MYSQL主庫的主從複製關係
mysql> change master to master_host='10.0.0.12',master_user='repl',master_password='system',master_log_file='binlog.000002',master_log_pos=120;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
13,在MYSQL從庫2 啟動主從複製服務
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
14,在MYSQL從庫2檢視主從複製執行
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.12
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000002
Read_Master_Log_Pos: 437
Relay_Log_File: standby2mysql-relay-bin.000003
Relay_Log_Pos: 280
Relay_Master_Log_File: binlog.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: 437
Relay_Log_Space: 938
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: 65fddb9f-fd33-11e9-95f0-080027d1f3fc
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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
1 row in set (0.00 sec)
ERROR:
No query specified
15,驗證MYSQL主庫與新部署的MYSQL從庫2 資料同步正常
--MYSQL主庫
mysql> use zxydb;
Database changed
mysql> insert into t_go select 5,5;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t_go;
+---+------+
| a | b |
+---+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 5 | 5 |
+---+------+
4 rows in set (0.00 sec)
---MYSQL從庫2
mysql> select * from zxydb.t_go;
+---+------+
| a | b |
+---+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 5 | 5 |
+---+------+
4 rows in set (0.00 sec)
16,在MYSQL主庫執行,可見現配置2個MYSQL從庫
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 3 | | 3306 | 1 | 699a379f-e36d-11e9-a4e2-0800274dcc79 |
| 2 | | 3306 | 1 | 891bc123-fd72-11e9-8cf5-080027dddbcd |
+-----------+------+------+-----------+--------------------------------------+
2 rows in set (0.00 sec)
大家可以關注我的微信公眾號,每天會定期傳送一些資料庫相關的文章,歡迎交流。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2662398/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL主從複製環境部署MySql
- 生產環境故障處理演練-mysql資料庫主從恢復MySql資料庫
- 生產環境中mysql資料庫由主從關係切換為主主關係MySql資料庫
- MySQL 5.7主從新增新從庫MySql
- MySQL Xtrabackup真實生產環境搭建主從複製全過程MySql
- 基於Linux的mysql主從配置LinuxMySql
- 【mysql】mysql的資料庫主從(一主一從)MySql資料庫
- 用 Docker 構建 MySQL 主從環境DockerMySql
- 基於GTID搭建主從MySQLMySql
- 基於Linux的docker mysql主從搭建LinuxDockerMySql
- Mysql 基於GTID主從複製MySql
- Windows 環境下,MySQL 的主從複製和主主複製WindowsMySql
- windows環境下,Mysql的主從複製和主主複製WindowsMySql
- mysql 基於日誌的主從複製MySql
- MySQL 5.7基於GTID的主從複製MySql
- docker部署mysql8主從DockerMySql
- Windows Mysql主從複製部署WindowsMySql
- MySQL常用操作和主從配置MySql
- MySQL原理簡介—3.生產環境的部署壓測MySql
- MySQL 5.7 基於GTID搭建主從複製MySql
- Mysql 從庫如果有未提交的事務主庫ddl操作導致主從延遲MySql
- mysql主從複製詳細部署MySql
- Mysql MHA部署-02主從複製MySql
- 揭祕MySQL 主從環境中大事務的傳奇事蹟MySql
- mysql主從資料庫配置MySql資料庫
- [資料庫]MYSQL主從同步資料庫MySql主從同步
- 基於 Docker 的 MySQL 主從複製搭建(真正弄懂)DockerMySql
- 基於docker環境下搭建redis主從叢集DockerRedis
- 手把手教你,如何在windows系統搭建mysql主從複製的環境WindowsMySql
- 10分鐘搞定Mysql主從部署配置MySql
- kubernetes使用StatefulSet部署mysql一主多從MySql
- MySQL 主從複製安裝部署配置MySql
- 基於MySql主從分離的程式碼層實現MySql
- 8、MySQL主從資料庫配置MySql資料庫
- 生產環境中MySQL複製的搭建KPMySql
- mysql主從搭建MySql
- mysql主從同步MySql主從同步
- mysql主從配置MySql