1. 程式人生 > >MySQL5.7基於mysqldump的主從複製

MySQL5.7基於mysqldump的主從複製

1建立賬號
建立用於複製的賬號
GRANT REPLICATION SLAVE ON . TO ‘repl’@’192.168.1.%’ IDENTIFIED BY PASSWORD ‘repl4salve’;
建立用於監控的賬號
grant replication client on . to ‘monitor’@’192.168.1.%’ identified by’m0n1tor’;
2 備份資料
[[email protected] backup]# mysqldump -uroot -hlocalhost -p -S /tmp/3306.sock –single-transaction –master-data=2 -A >3306.sql
Enter password:
[

[email protected] backup]# ls
3306.sql
[[email protected] backup]# more 3306.sql

– MySQL dump 10.13 Distrib 5.7.9, for linux-glibc2.5 (x86_64)

– Host: localhost Database:

– Server version 5.7.9-log

/!40101 SET @[email protected]@CHARACTER_SET_CLIENT /;
/!40101 SET @[email protected]

@CHARACTER_SET_RESULTS /;
/!40101 SET @[email protected]@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8 /;
/!40103 SET @[email protected]@TIME_ZONE /;
/!40103 SET TIME_ZONE=’+00:00’ /;
/!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0
/;
/!40101 SET @[email protected]@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ /;
/!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 /;

– Position to start replication or point-in-time recovery from

CHANGE MASTER TO MASTER_LOG_FILE=’mysql-bin.000006’, MASTER_LOG_POS=154;


記錄下這個位置在slave中有用到

將生成的檔案匯入到node2中
[[email protected] backup]# scp 3306.sql node2:/data/mysql/backup
[email protected]’s password:
3306.sql 100% 703KB 703.0KB/s 00:00

在node2中講資料匯入到db中
(product)[email protected] [(none)]> source /data/mysql/backup/3306.sql

(product)[email protected] [mysql]> flush privileges; 重新整理一下許可權,因為user表也會到過來的 需要flush許可權才會有效
Query OK, 0 rows affected (0.00 sec)

編寫change master 語句:

(product)root@localhost [mysql]> change master to master_host='192.168.1.101',
                                                                                   master_port=3306,
                                                                                   master_user='repl',
                                                                                   master_password='repl4slave',
                                                                                   master_log_file='mysql-bin.000006',
                                                                                   master_log_pos=154;

上面的logfile和logpos的的值就是 dump出來的值。

(product)[email protected] [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

(product)[email protected] [(none)]> show slave status \G

***************** 1. row *****************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 154
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000006
**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: 521
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: 1013306
Master_UUID: 5671c0ed-8297-11e5-a0c3-000c2972e7f3
Master_Info_File: /data/mysql/mysql3306/data/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:
1 row in set (0.00 sec)

這裡都是yes的表示執行成功
然後測試一下:
在node1中插入資料:
[[email protected] mysql3306]# sh start_mysql.sh
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.9-log MySQL Community Server (GPL)

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.

(product)[email protected] [(none)]> use db_1;
Database changed
(product)[email protected] [db_1]> select * from tb_1;
+—-+——+
| id | name |
+—-+——+
| 1 | aa |
| 2 | bb |
| 3 | c |
| 4 | dd |
| 5 | ee |
| 6 | ff |
| 7 | g |
| 8 | hh |
+—-+——+
8 rows in set (0.00 sec)

(product)[email protected] [db_1]> insert into tb_1 (name) values(‘cc’);
Query OK, 1 row affected (0.01 sec)
在node2中查詢是否有資料進入:
[[email protected] mysql3306]# sh start_mysql.sh
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.9-log MySQL Community Server (GPL)

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.

(product)[email protected] [(none)]> use db_1;
Database changed
(product)[email protected] [db_1]> select * from tb_1;
+—-+——+
| id | name |
+—-+——+
| 1 | aa |
| 2 | bb |
| 3 | c |
| 4 | dd |
| 5 | ee |
| 6 | ff |
| 7 | g |
| 8 | hh |
| 9 | cc |
+—-+——+
9 rows in set (0.00 sec)

主從複製建立成功

需要注意的是在這個複製過程中binlog的格式必須是一致的。
還有要把機器的 防火牆和selinux關閉掉。否則會報錯的!!
在5.7中防火牆關閉:
systemctl start firewalld.service#啟動firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall開機啟動
原來的iptables被firewall代替了。

相關推薦

MySQL5.7基於mysqldump主從複製

1建立賬號 建立用於複製的賬號 GRANT REPLICATION SLAVE ON . TO ‘repl’@’192.168.1.%’ IDENTIFIED BY PASSWORD ‘repl4salve’; 建立用於監控的賬號 grant repl

MySQL5.7.23,主從複製的使用

先確保兩件事情,1. 主從資料庫版本最好一致,以免出現莫名其妙的問題。 2. 主從資料庫之間網路聯通沒有問題。因為我是單配置檔案部署的MySQL多例項,所以不存在這兩個問題。 一、修改配置檔案。 主資料庫配置,新增以下資訊 #主從複製配置 server-id=1 #設

Docker安裝mysql5.7並且配置主從複製

轉載請表明出處 https://blog.csdn.net/Amor_Leo/article/details/85177001 謝謝 Docker安裝mysql5.7並且配置主從複製 拉取mysql映象 建立檔案docker.cnf

Centos7安裝mysql5.7並且配置主從複製

轉載請表明出處 https://blog.csdn.net/Amor_Leo/article/details/85161624 謝謝 Centos7安裝mysql5.7並且配置主從複製 安裝Mysql 清除Centos7的預設資料庫ma

CentOS7x64配置MYSQL5.7 Master Slave主從複製

@1首先修改mysql配置檔案  /etc/my.cnf #ID 必須唯一 server-id=1 #二進位制檔名稱字首,生成的檔案mysql-bin.000001,mysql-bin.000002 log-bin=mysql-bin #記錄目前有哪些mysql-bi

mysql5.7——基於GTID的主從複製

在上一篇部落格中我們介紹了mysql5.7主從複製的原理和配置,今天我們就在上一篇部落格的基礎上來看看基於GTID的mysql5.7主從複製與半同步複製是什麼樣的 GTID 概述 GTID(Global Transaction ID)是MySQL5.6引入的功能,可以在叢集全域性

MySQL5.7安裝+基於GTID主從複製+並行複製+增強半同步複製+讀寫分離+M-S-S架構(聯級複製

實驗環境: Centos7.2 角色 主機IP server_id 資料狀態 Proxysql 192.168.148.62 nul

MySQL5.7主從複製基於GTID主從複製、半同步、組複製、全同步解析

一、主從複製 1.環境 系統:redhat6.5 防火牆:保持關閉 selinux=disabled mysql主機:server1 172.25.32.4/24 mysql從機:server2 172.25.32.5/24 2.MySQL

MySQL5.7--------基於無損復制搭建主從

mysql dba lossless 1. 背景 * MySQL Replication默認都是異步(asynchronous),當主庫在執行完一些事務後,是不會管備庫的進度的。如果備庫不幸落後,而更不幸的是主庫此時又出現Crash(例如宕機),這時備庫中的數據就是不完整的。簡而言之,在主庫發

MYSQL5.7基於SSL的主從復制

增刪改 安全性 二進制 技術分享 mysql5 傳輸數據 nlog binlog 存儲引擎 本文檔使用的是mysql版本為5.7.22,linux內核為3.10.0-862.el7.x86_64。一、首先主從復制的原理:1、master服務器的binary log(二進制)

MySQL5.7--------基於CentOS6二進制包安裝

mysql dba mysql5.7 1. 背景 * MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB 公司開發,目前屬於 Oracle 旗下產品。MySQL 是最流行的關系型數據庫管理系統之一,在 WEB 應用方面,MySQL是最好的 RDBMS (Relational Databa

MySQL5.7配置GTID主從---搭建GTID主從

ria lan 導出表 ack channel 說明 其中 添加 需要 準備說明: master:192.168.10.100 slave:192.168.10.101 一、配置GTID參數 配置文件均為/etc/my.cnf Master參數配置: gtid-mode

mysql 5.7 基於GTID 主從同步的1236故障處理(其它事務故障等同)

其它 top 處理 set tid gtid stop eve 1-1 登錄從庫 stop slave; 查看執行事務 show slave status\G Retrieved_Gtid_Set: ee3bdb44-f6a1-11e7-b194-005056a35fd4

效能提升利器:MySQL 5.7多源主從複製的獨特性

作者介紹 高強,DBAplus社群聯合發起人,開源技術專家。擅長MySQL、PostgreSQL等產品的實施、運維和故障處理。曾參與多個省級政府單位專案的實施和運維工作,具有豐富的運維經驗。 關於MySQL主從複製 複製技術顧名思義,就是通過資料庫的複製技術以一份資料為主,複製成另一份存放,資料來源

Centos7 下關於MySQL5.7.22的主從部署

create database energy_system default character set utf8 collate utf8_general_ci; create database energy_battery_supplier default character set utf8 collat

Centos7 安裝mysql5.7 (基於騰訊雲)

                前言:寫部落格是作者對問題的理解與解決,不要認為複製貼上就是自己的。  如需轉載請標明出處 1.使用xftp工具將官網下載的rpm檔案包上傳至自己伺服器(注意自己lin

mycat搭建 基於 mysql主從複製

mycat    mycat只是一箇中間件,邏輯上的資料庫,在實際應用開發中,需要搭建mysql 的主從複製mysql主從複製的搭建    傳統的mysql主從複製有許多的缺點, 它是基於logbin日誌檔案讀入來實現主和從的資料一致,詳細的搭建過程可以參見這種搭建十分簡單,

mysql主從複製基於GTID主從複製,並行複製,半同步複製

複製方式: 主–從複製(A-B一主一從或者A-BC一主多從) 基於GTID複製 非同步複製 半同步複製 複製原理: Mysql中有一種日誌叫做bin日誌(二進位制日誌)。這個日誌會記錄下所有修改了資料庫的SQL語句 主從複製的原理其實就是把主伺服器上的bin日

運維筆記36 mysql的一主多從模型(原始主從複製基於GTID主從複製

概述: mysql的主從複製是十分經典的一個應用,但是主從之間總會有資料一致性(data consistency )的問題,一般情況從庫會落後主庫幾個小時,而且在傳統一主多從(mysql5.6之前)的模型中當master down掉後,我們不只是需要將一個sl

centos7安裝mysql5.7並配置主從

一、mysql基礎安裝 1、系統約定: 安裝檔案下載目錄:/data/software Mysql目錄安裝位置:/usr/local/mysql 資料庫儲存位置:/data/mysql 日誌儲存位置:/data/log/mysql 2、列出所有被安裝的rpm p