1. 程式人生 > >mysql之 mysql 5.6不停機主從搭建(一主一從基於日誌點複製)

mysql之 mysql 5.6不停機主從搭建(一主一從基於日誌點複製)

環境說明:
版本 version 5.6.25-log 
主庫ip: 10.219.24.25
從庫ip:10.219.24.22
os 版本: centos 6.7
已安裝熱備軟體:xtrabackup 
防火牆已關

補充:

主從複製原理: http://blog.csdn.net/zhang123456456/article/details/72972701
mysql 5.6安裝 :http://blog.csdn.net/zhang123456456/article/details/53608554
xtrabackup 安裝: http://blog.csdn.net/zhang123456456/article/details/72836184

一主一從搭建流程:

1、 主庫引數調整
-- 停止主庫mysql
[[email protected] ~]# service mysql stop
[[email protected] ~]# netstat -nltp|grep mysql|grep 3606
-- 調整 my.cnf 引數
[[email protected] ~]# cat /etc/my.cnf
[client]
password = oracle
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server-id=25
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql
log_bin = /data/mysql/binarylog/binlog 
log_bin_index = /data/mysql/binarylog/binlog
binlog_format = mixed
innodb_data_file_path = ibdata1:12M:autoextend 
[mysql]
default-character-set = utf8
說明:主庫必須配置的引數
server-id (主從的server-id必須不同)、log_bin、binlog_format 

-- 啟動主庫
[[email protected] ~]# mysqld_safe --defaults-file=/etc/my.cnf &
2、 從庫引數調整
-- 停止從庫mysql
[[email protected] ~]# service mysql stop
[[email protected] ~]# netstat -nltp|grep mysql|grep 3606
-- 調整 my.cnf 引數
[[email protected] ~]# cat /etc/my.cnf
[client]
password = oracle
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server-id=22
port = 3306
socket = /data/mysql/mysql.sock
character_set_server = utf8
character_set_client = utf8
collation-server=utf8_general_ci
lower_case_table_names = 1
max_connections = 1000
datadir = /data/mysql
log_bin = /data/mysql/binarylog/binlog 
log_bin_index = /data/mysql/binarylog/binlog
relay-log = /data/mysql/relaylog/relay
relay-log-index = /data/mysql/relaylog/relay
relay_log_purge = on
read-only = 1
[mysql]
default-character-set = utf8
說明:從庫必須配置的引數
server-id、log_bin、relay-log、read-only

3、 主庫備份
-- 主庫備份目錄
[[email protected] full]# pwd
/xtrabackup/full
-- 主庫 innobackupex 備份
[[email protected] ~]# innobackupex --user=root --password=oracle --port=3606 /xtrabackup/full/
170610 17:50:23 Backup created in directory '/xtrabackup/full/2017-06-10_17-50-19/'
MySQL binlog position: filename 'binlog.000010', position '120'
....
170610 17:50:23 completed OK!
-- 檢視備份 binlog編號 與 截止 position
[[email protected] 2017-06-10_17-50-19]# cat xtrabackup_binlog_info 
binlog.000010 120

4、 從庫建立與主庫相同的備份目錄
[[email protected] ~]# mkdir -p /xtrabackup/full
[[email protected] ~]# chown -R mysql:mysql /xtrabackup/full/

5、 主庫將備份 scp 到從庫
[[email protected] full]# pwd
/xtrabackup/full
[[email protected] full]# scp -r 2017-06-10_17-50-19 10.219.24.22:/xtrabackup/full
6、 從庫檢視scp過來的備份
[[email protected] ~]# cd /xtrabackup/full/2017-06-10_17-50-19/
[[email protected] 2017-06-10_17-50-19]# ll
total 12320
-rw-r-----. 1 root root 419 Jun 10 18:01 backup-my.cnf
-rw-r-----. 1 root root 12582912 Jun 10 18:01 ibdata1
drwxr-x---. 2 root root 4096 Jun 10 18:01 mysql
drwxr-x---. 2 root root 4096 Jun 10 18:01 performance_schema
drwxr-x---. 2 root root 4096 Jun 10 18:01 test
-rw-r-----. 1 root root 18 Jun 10 18:01 xtrabackup_binlog_info
-rw-r-----. 1 root root 113 Jun 10 18:01 xtrabackup_checkpoints
-rw-r-----. 1 root root 482 Jun 10 18:01 xtrabackup_info
-rw-r-----. 1 root root 2560 Jun 10 18:01 xtrabackup_logfile

7、 主庫建立同步使用者
mysql> GRANT replication slave ON *.* TO 'slave25'@'%' IDENTIFIED BY 'oracle'; 
Query OK, 0 rows affected (0.05 sec)

8、 從庫恢復主庫資料
-- 從庫將原有datadir資料夾重新命名到新位置,並建立原資料夾 
[[email protected] ~]# mv /data/mysql /data/mysqlbak
[[email protected] ~]# mkdir -p /data/mysql
-- innobackupex apply-log
[[email protected] ~]# innobackupex --apply-log --user=oracle \
--password=oracle --port=3606 /xtrabackup/full/2017-06-10_17-50-19/
-- innobackupex copy 恢復的檔案到原來的資料位置
[[email protected] mysql]# innobackupex --defaults-file=/etc/my.cnf --user=root \
--copy-back /xtrabackup/full/2017-06-10_17-50-19/

170610 18:25:11 completed OK!
-- 建立binlog目錄與 relaylog 目錄並賦權
[[email protected] ~]# mkdir -p /data/mysql/binarylog
[[email protected] ~]# mkdir -p /data/mysql/relaylog/
[[email protected] mysql]# chown -R mysql:mysql /data/mysql

9、 從庫配置與檢測
-- 從庫啟動
[[email protected] mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
-- 從庫指定與主庫同步的基本資訊
mysql>
change master to
master_host='10.219.24.25',
master_port=3306,
master_user='slave25',
master_password='oracle', 
master_log_file='binlog.000010',
master_log_pos=120; 
Query OK, 0 rows affected, 2 warnings (0.04 sec)

引數解釋:
MASTER_HOST : 設定要連線的主伺服器的ip地址
MASTER_USER : 設定要連線的主伺服器的使用者名稱
MASTER_PASSWORD : 設定要連線的主伺服器的密碼
MASTER_LOG_FILE : 設定要連線的主伺服器的bin日誌的日誌名稱
MASTER_LOG_POS : 設定要連線的主伺服器的bin日誌的記錄位置
-- 啟動slave 狀態(開始監聽msater的變化)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
-- 檢視slave的狀態.
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.219.24.25 #主庫 IP
Master_User: slave25 # 主庫複製的使用者
Master_Port: 3306 # 主庫 mysqld 
Connect_Retry: 60
Master_Log_File: binlog.000010 #io_thread 讀取主庫 master_log_file
Read_Master_Log_Pos: 717 # io_thread 讀取主庫 master_log_pos
Relay_Log_File: relay.000002
Relay_Log_Pos: 877
Relay_Master_Log_File: binlog.000010 #sql_thread 執行主庫的 master_log_file
Slave_IO_Running: Yes # 關鍵的,io_thread 是否 running 
Slave_SQL_Running: Yes # 關鍵的,sql_thread 是否 running
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: 717 #sql_thread 執行主庫的 master_log_pos
Relay_Log_Space: 1040
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: 25
Master_UUID: 29d68531-4cf9-11e7-8e1f-000c297c4100
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 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


10、 主從同步檢查 
-- 主庫
mysql> create database repl;
Query OK, 1 row affected (0.00 sec)
mysql> use repl
Database changed
mysql> create table repl (id int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into repl values(1);
Query OK, 1 row affected (0.00 sec)

-- 從庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| binarylog |
| mysql |
| performance_schema |
| relaylog |
| repl |
| test |
+--------------------+
7 rows in set (0.00 sec)
mysql> use repl
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from repl;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec) >同步成功!

相關推薦

mysql mysql 5.6停機主從搭建基於GTID復制

從庫 creat 不停機 event rep ply copy from end 環境說明:版本 version 5.6.25-log 主庫ip: 10.219.24.25從庫ip:10.219.24.22os 版本: centos 6.7已安裝熱備軟件:xtrabacku

mysql mysql 5.6停機主從搭建基於日誌複製

環境說明: 版本 version 5.6.25-log  主庫ip: 10.219.24.25 從庫ip:10.219.24.22 os 版本: centos 6.7 已安裝熱備軟體:xtrabackup  防火牆已關 補充: 主從複製原理: http://blog.

mysql mysql 5.6停機搭建活躍雙基於日誌復制

stat 5.6 create 文件夾 eat ima send spec tar 環境說明:版本 version 5.6.25-log 主1庫ip: 10.219.24.25主2庫ip: 10.219.24.22從1庫ip:10.219.24.26os 版本: cento

MySQL 5.6 的 半同步複製搭建已糾正

# The following options will be passed to all MySQL clients [client] #password       = your_password port            = 3306 socket          = /tmp/my

mysql MySQL 主從基於 GTID 復制原理概述

發送 重要 導致 ora 允許 減少 自動同步 一次 插入數據 一、 什麽是GTID ( Global transaction identifiers ):MySQL-5.6.2開始支持,MySQL-5.6.10後完善,GTID 分成兩部分,一部分是服務的UUid,UUID

windows下安裝mysqlmysql-installer-community-5.6.10.1

自動 選擇 devel 界面 mysql-in for 選項 需要 acc 轉載 2015年06月07日 18:22:57 轉載自:http://blog.sina.com.cn/s/blog_7cecec9501017cmk.html 一、安裝前的準備

mysql-5.6.40 源碼安裝Centos6.6

文件 start 方式 sql命令 相關 dde rpm include star 1. 檢測系統是否自帶有mysql [root@shu1024 ~]# rpm -qa|grep mysql mysql-libs-5.1.73-3.el6_5.x86_64 若有則卸載

MySql 5.6.21安裝及配置超詳細

cal 開始 流程 重復 配置 路徑 進行 驗證 高級 一、安裝    ----->點擊接受協議 ----->下一步    這裏選擇我只需要安裝服務器,因此選擇 Server only -------->下一步    -------->點擊execu

CentOS7.4下使用通用二進制文件安裝MySQL Community Server 5.6.41

prevent 服務 password security 添加mysql用戶 用戶組 tmp 下使用 .cn 1、卸載自帶MySQL rpm -qa | grep mysqlrpm -e --nodeps mysql* 2、添加mysql用戶和用戶組 groupadd my

Error: Package: mysql-community-server-5.6.41-2.el7.x86_64 (mysql56-community) Requires:

http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html    MySQL登陸失敗:ERROR 2002 (HY000): Can't connect to local MySQL

用zip安裝包在win 10安裝mysql community server 5.6.33(64bit)的過程

原來用MSI方式安裝了MySql 5.7版,因需要(貌似對vs2015+mvc+mysql+ef不太支援),御載後重裝5.6.33版(64bit),並希望將資料庫資料檔案儲存目錄設定為d:\mysqldata。作業系統是win10(64bit)。 1)下載zip 開啟htt

mysql高版本5.65.5或低版本複製中出現的錯誤

在高版本啟動時,忘記配置binlog_checksum引數,會導致生成的binlog中有校驗演算法的日誌,當從庫版本低於主庫,就會報錯 看下面忘記新增引數時,解析的binlog 修改my.cnf檔案或動態修改set global  binlog_checksum=no

mysql 半同步 5.65.7

5.6mysql半同步複製的原理圖 通過圖片,我們看到,當master提交事務時,並不等待slave節點確認。所以並不保證slave節點的事務是否也能commit成功(例如duplicate key error)。因此可能出現主庫提交的資料,從庫看不到的現

mysql-5.6.37-winx64安裝記錄安裝雙版本mysql

機器上現在已經存在5.0版本mysql的情況下,繼續安裝一個最新版的mysql. 一、官網下載免安裝壓縮包。 下載地址 本人下載的是mysql-5.6.37-winx64.zip.將壓縮包解壓到自定義目錄中。例如:D:\mysql-5.6.37. 二、新增環境變數.

mysql mysql數據庫壓力測試工具mysqlslap

root .cn this 用戶 cas bench 測試 逗號 complete mysqlslap是從MySQL的5.1.4版開始就開始官方提供的壓力測試工具。通過模擬多個並發客戶端並發訪問MySQL來執行壓力測試,同時提供了較詳細的SQL執行數據性能報告,並且能很好的

MySQL主從MySQL proxy Lua讀寫分離設置,同步配置,分庫分表方案

否則 count user username 2個 ons 基礎 zxvf 路徑 Mysql Proxy Lua讀寫分離設置一.讀寫分離說明讀寫分離(Read/Write Splitting),基本的原理是讓主數據庫處理事務性增、改、刪操作(INSERT、UPDATE、DE

MySQLmysql命令使用詳解

common follow for page zed rds wait sca dex MySQL Name mysql - the MySQL command-line tool Synopsis mysql [options] db_name Descripti

MySQL主從配置:主從介紹、配置 、測試主從同步

mysql主從配置 MySQL主從介紹(兩臺機器數據同步)主:-->binlog從:-->relaylog主上有一個log dump線程,用來和從的I/O線程傳遞binlog 從上有兩個線程,其中I/O線程用來同步主的binlog並生成relaylog,另外一個SQL線程用來

CentOS6.5配置MYSQL詳解

ali ati In restart 配置文件 left 主庫 vim 數據庫 一、環境 1 操作系統 :CentOS 6.5 2 數據庫版本:MySQL 5.6.27 3 主機A:192.168.1.1 (Master) 4 從機B:192.168.1.2 (

Centos7配置mysql主從

表結構 .cn single 讀取 entos body 分享 posit bin-log mysql主從復制原理1.首先master將數據更新記錄到二進制binlog文件2.slave通過I/O線程向master請求binlog日誌文件指定位置之後的內容3.master接