學習筆記(14):MySQL版SQL優化-主從同步實戰

立即學習:https://edu.csdn.net/course/play/25283/297163?utm_source=blogtoedu

實現主從同步(主從複製):

同步的核心:二進制日誌

1.  master   將改變的數  記錄在本地的  二進制日誌中(binary log);該過程稱之爲:二進制日誌事件

2.slave  將master的binary log 拷貝到自己的relay log (中繼日誌文件)中 

3.中繼日誌事件,將數據讀取到自己數據庫之中

MySQL主從複製   是異步的,串行化的,有延遲

master:slave  =1:n

 

配置:

windows(mysql:mysql.ini)

linux  (mysql:my.cnf)

配置前,爲了無誤,先將權限(遠程訪問)、防火牆等處理;

關閉windows/linux  防火牆

mysql 允許遠程連接(windows /linux)

Grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

flush privileges;

 

server-id=1  唯一標識;

二進制日誌文件

log-bin="data 目錄 下/mysql-bin"

錯誤記錄文件

 log-error="data 目錄 下/mysql-error"

主從同步時忽略的數據庫

binlog-ignore=mysql(忽略的數據庫)

指定主從同步時,同步哪些數據庫

binlog-do-db=test(只同步這一個

 

Windows  中的數據庫  授權哪臺計算機中的數據庫是自己的從數據庫; 

 

主庫中執行

grant repliacation slave,reload,super on *.* to 'root'@'192.168.%.%' identified by 'root';

flush privileges;

 

從庫執行:

show slave status \G 

如果不都是yes  ,需要看下方的Last_Io_Error日誌,

 

檢查 server-id:show variables like 'server_id'

 

set  global server-id=2;通過全局變量修改server-id;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章