MySQL異步復制

準備:主備庫版本一致,正常安裝軟件。

1、主庫上設置一個復制使用的賬戶:

mysql> grant replication slave on *.* to 'rep1'@'192.168.100.136' identified by 'dbking';

Query OK, 0 rows affected (0.18 sec)

mysql> select user,host,password from mysql.user where user='rep1';

+------+-----------------+-------------------------------------------+

| user | host??????????? | password????????????????????????????????? |

+------+-----------------+-------------------------------------------+

| rep1 | 192.168.100.136 | *0E5B9DDCEF035D1E653099F4143C0F36061F7653 |

+------+-----------------+-------------------------------------------+

1 row in set (0.08 sec)

2、修改主庫參數文件,開啟binlog并設置slave id:

log_bin=/usr/local/mysql/data/dbking-bin.log

server_id=1

3、主數據庫上設置讀鎖定有效:

mysql> flush tables with read lock;

Query OK, 0 rows affected (0.00 sec)

4、然后得到主數據庫上當前二進制日志文件及偏移量,為了在從庫復制起點:

mysql> show master status;

+-------------------+----------+--------------+------------------+-------------------+

| File????????????? | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+-------------------+----------+--------------+------------------+-------------------+

| dbking-bin.000001 |????? 120 |????????????? |????????????????? |?????????????????? |

+-------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

5、主數據庫目前已停止更新操作,現在要得到主數據庫備份到從庫上恢復:

[root@chavinking mysql]# tar -cvf data.dir data

6、解鎖主庫:

mysql> unlock tables;

Query OK, 0 rows affected (0.00 sec)

7、將主庫備份恢復到從庫:

[root@chavinking mysql]# mv data data1204

[root@chavinking mysql]# tar -xvf data.dir

8、修改從庫my.cnf文件,設置server_id參數,server_id參數必須唯一:

server_id=2

9、從庫使用--skip-slave-start啟動數據庫:

[root@chavinking mysql]# bin/mysqld_safe --skip-slave-start &

[1] 18389

[root@chavinking mysql]# 161202 08:50:16 mysqld_safe Logging to '/usr/local/mysql/data/chavinking.err'.

161202 08:50:16 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

10、對從庫數據庫服務器進行相應設置,制定復制使用賬戶,主庫ip,端口以及開始進行復制的日志文件和位置等,具體如下:

wps58F2.tmp

本次試驗腳本如下:

mysql> change master to

??? -> master_host='192.168.80.133',

??? -> master_user='rep1',

??? -> master_password='dbking',

??? -> master_port=3306,

??? -> master_log_file='dbking-bin.000001',

??? -> master_log_pos=120;

Query OK, 0 rows affected, 2 warnings (0.11 sec)

11、從庫啟動slave線程:

mysql> start slave;

Query OK, 0 rows affected (0.11 sec)

12、從庫上查看配置信息:

mysql> show slave status \G;

*************************** 1. row ***************************

?????????????? Slave_IO_State: Waiting for master to send event

????????????????? Master_Host: 192.168.80.133

????????????????? Master_User: rep1

????????????????? Master_Port: 3306

??????????????? Connect_Retry: 60

????????????? Master_Log_File: dbking-bin.000004

????????? Read_Master_Log_Pos: 120

?????????????? Relay_Log_File: chavinking-relay-bin.000008

??????????????? Relay_Log_Pos: 284

??????? Relay_Master_Log_File: dbking-bin.000004

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: 120

????????????? Relay_Log_Space: 510

????????????? 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: 9b92b2a8-b7e0-11e6-81e4-000c29fa5a95

???????????? Master_Info_File: /usr/local/software/mysql-5.6.24-linux-glibc2.5-x86_64/data/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)

如果其中Slave_IO_Running: NO,并且日志文件報錯:

2016-12-02 11:19:37 19637 [ERROR] Slave I/O: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: 1593

那么修改data目錄下的auto.cnf文件后重啟數據庫即可解決。

轉載于:https://www.cnblogs.com/wcwen1990/p/6655329.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/393317.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393317.shtml
英文地址,請注明出處:http://en.pswp.cn/news/393317.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

開源一個爬取redmine數據的測試報告系統

背景 軟件測試的最后有一道比較繁瑣的工作,就是編寫測試報告。手寫測試報告在數據統計和分析上面要耗費比較大的事件和精力。之前工作室使用mantis管理bug缺陷。公司有內部有個系統,可以直接從mantis上面獲取數據并進行統計,生成一份測試報告…

java cxf 雙向通訊_CXF 在spring boot 2 發布多個服務

0. 問題來源之前配置cxf服務端都是在spring 3以下,后來使用spring mvc 還都是基于xml的配置文件模式,在springboot模式下,實現起來更為簡單了。此次記錄下spring boot 2下的實現方式。1. 準備工作項目中,直接拉入spring boot cxf相…

小程序 堅屏_如何構建堅如磐石的應用程序

小程序 堅屏不同的應用程序設計選項概述 (An overview of different app design options) When we design software, we constantly think about error cases. Errors have a huge impact on the way we design and architecture a solution. So much so, in fact, that there …

C# 分層

三層架構分為:表現層(UI)、業務邏輯層(BLL)、數據訪問層(DAL)再加上實體類庫(Model) 轉載請注明出自朱朱家園http://blog.csdn.net/zhgl7688 1、實體類庫(Mod…

leetcode1177. 構建回文串檢測(前綴和)

給你一個字符串 s,請你對 s 的子串進行檢測。 每次檢測,待檢子串都可以表示為 queries[i] [left, right, k]。我們可以 重新排列 子串 s[left], …, s[right],并從中選擇 最多 k 項替換成任何小寫英文字母。 如果在上述檢測過程中&#xf…

java界面化二叉排序樹_層次序創建二叉樹(圖形界面和控制臺輸入實現)

1 2018.11.72 XT34 /**5 * 功能:構造二叉樹6 * 說明:7 * 1.主函數輸入模式有兩種,BT參數 true 圖形界面,false 控制臺輸入8 * 2.構造樹是按層次遍歷結果輸入的 如:ABCDE*F**GH9 */1011 import javax.swing.*;12 import…

web開發環境_Web開發人員的開發環境

web開發環境With all the tools and programs available, it can be challenging to figure out the best way to set up your development environment on your computer.使用所有可用的工具和程序,尋找在計算機上設置開發環境的最佳方法可能是一項挑戰。 In this…

使用.net Stopwatch class 來分析你的代碼

當我們在調試,優化我們的代碼的時候,想知道某段代碼的真正的執行時間,或者我們懷疑某段代碼,或是某幾段代碼執行比較慢, 需要得到具體的某段代碼的具體執行時間的時候。有一個很好用的類Stopwatch。 Stopwatch 類在 Sy…

Docker 部署 postgresql 與 pgadmin4

Docker快速部署PostgreSQL服務 快速開始 請新建一個目錄postgresql,進入目錄postgresql,將以下文件保存為docker-compose.yml,然后執行docker-compose up version: 3 services:mydb:image: postgres:11volumes:- db-data:/var/lib/postgresql…

leetcode151. 翻轉字符串里的單詞

給定一個字符串&#xff0c;逐個翻轉字符串中的每個單詞。 示例 1&#xff1a; 輸入: “the sky is blue” 輸出: “blue is sky the” 代碼 class Solution {public String reverseWords(String s) {int ns.length(),i0;ArrayList<String> arrayListnew ArrayList<…

java衍生作用_java-如何從AffineTransform衍生的形狀對象中“...

您可以使用AffineTransform.transform(Point2D, Point2D)變換多邊形上的單個點.如果您不使用旋轉變換來移動船,而是將船的位置保持在一個(x,y)位置,那么事情就簡單得多.您可以在move()中移動飛船的位置,而不是嘗試平移多邊形.然后,當您想給船上油漆時,例如做&#xff1a;// Opt…

初學者設計數據庫_面向初學者的完整數據庫設計課程

初學者設計數據庫This database design course will give you a deeper grasp of database design. Caleb Curry teaches the equivalent of an entire college course during this eight hour video.本數據庫設計課程將使您更深入地了解數據庫設計。 在這8個小時的視頻中&…

Qt QTcpSocket使用總結

socket的連接是異步的&#xff0c;所以必須等連接建立完成才能使用&#xff0c;所以分別加入waitForConnected()和waitForBytesWritten()后調試通過1&#xff09;只有使用waitForConnected()后,QTcpSocket才真正嘗試連接服務器&#xff0c;并返回是否連接的結果2&#xff09;避…

[bzoj1303][CQOI2009]中位數圖

來自FallDream的博客&#xff0c;未經允許&#xff0c;請勿轉載&#xff0c;謝謝。 給定一個n個數排列&#xff0c;求有多少段長度為奇數的區間&#xff0c;中位數是b. n<100000 時間限制0.1s 我一開始沒看到排列&#xff0c;想著怎么還能O(n)做的啊&#xff1f;&#xff1f…

falsk 請求沒有返回值報錯

線上報警 5xx 錯誤&#xff0c;查看日志發現報這個錯&#xff0c; TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement. 這個方法沒有有效的返回結果 頁面報這個錯誤 Internal Server Err…

java的iterator接口_java Iterator接口和LIstIterator接口分析_java_腳本之家

java Iterator接口和LIstIterator接口分析目錄1.Iterator接口2.ListIterator3.Iterator和ListIterator的區別正文在繼續看ArrayList源碼之前&#xff0c;先了解Iterator接口和ListIterator接口&#xff0c;下篇文章詳細講解ArrayList是如何實現它們的。我們知道&#xff0c;接…

leetcode468. 驗證IP地址

編寫一個函數來驗證輸入的字符串是否是有效的 IPv4 或 IPv6 地址。 IPv4 地址由十進制數和點來表示&#xff0c;每個地址包含4個十進制數&#xff0c;其范圍為 0 - 255&#xff0c; 用(".")分割。比如&#xff0c;172.16.254.1&#xff1b; 同時&#xff0c;IPv4 地…

播客#45:迪倫·以色列

On todays episode, I interview Dylan Israel. Dylan is a software engineer, a YouTuber, and the creator of several programming courses.在今天的一集中&#xff0c;我采訪了迪倫以色列。 迪倫(Dylan)是一位軟件工程師&#xff0c;一名YouTuber&#xff0c;并且是幾門編…

PHPstorm快捷鍵

當前文件搜索類&#xff1a;ctrln 全文檢索文件&#xff1a;ctrlshiftn 收起側邊欄&#xff1a;alt1&#xff08;自定義&#xff09; 個人學習記錄&#xff0c;持續更新中。。。 轉載于:https://www.cnblogs.com/zaijiang/p/7806260.html

JS基礎_強制類型轉換-Number

https://www.cnblogs.com/ZHOUVIP/p/7225267.html轉載于:https://www.cnblogs.com/robinunix/p/11011188.html