mysql的主從熱備份
Server version: 5.7.22-log OS: master(windows10企業版20H2)-->slave(windows10企業版LTSC1809)
mysql的權限及必要點
1,任意ip可以連接配接2個資料庫
-->>grant all on *.* to root@'%' identified by '[root密碼]';
2,2個資料庫的的庫名,庫中的結構要相同
-->>借助Navicat進行結構,資料同步
log-bin=mysql.bin # 使binlog在每N次binlog寫入後與硬碟同步 sync-binlog=1 # 1天時間自動清理二進制日志 expire_logs_days=1 # 需要同步的資料庫 binlog-do-db=master binlog-do-db=hbwlw # 不需要同步的資料庫 binlog-ignore-db = information_schema binlog-ignore-db = mysql binlog-ignore-db = performance-schema binlog-ignore-db = sys # Error Logging. log-error="WIN-11.1.1.197.err" # Server Id server-id=197
# Server Id. server-id=161 # bind-address=11.1.1.161 log_bin=mysql-bin # 二進制日志自動删除的天數
主庫mysql的配置
1,建立同步使用者(back是mysql使用者名,back123是密碼,11.1.1.161是從庫的IP位址)
-->>grant replication slave on *.* to 'back'@'11.1.1.161' identified by '[對應密碼 ]';
2,重新整理權限
-->>flush privileges;
3,添加測試資料庫
create database test; use test; create table test(id int(11), value varchar(20)); insert into test values(1, 'aa'),(2, 'bb'),(3, 'cc') ,(4, 'dd') ,(5, 'ff')
4,檢視master的狀态(牢記File,Position)
-->>show master status \G
從庫mysql的配置
1,建立同步使用者并修改權限
-->>grant all privileges on *.* to 'back'@'%' identified by '[對應密碼]' with grant option;
2,連接配接master主庫
-->>change master to master_host='[主庫IP]',master_user='同步用的user',master_password='對應passwd', master_log_file='[master status 中的file]',master_log_pos=[master status 中的Position];
3,檢查slave的狀态
-->>show salve status \G
總結
slave IO和SQL狀态都為'YES'則同步成功