Linux下指定mysql數(shù)據(jù)庫數(shù)據(jù)配置主主同步的實(shí)例
一、 概念:
① 數(shù)據(jù)庫同步 (主從同步 --- 主數(shù)據(jù)庫寫的同時(shí) 往從服務(wù)器寫數(shù)據(jù))
② 數(shù)據(jù)庫同步 (主主同步 --- 兩臺(tái)數(shù)據(jù)庫服務(wù)器互相寫數(shù)據(jù))
二、 舉例
主主數(shù)據(jù)庫同步服務(wù)器配置
數(shù)據(jù)庫服務(wù)器(A) 主數(shù)據(jù)庫 IP:192.168.1.134
數(shù)據(jù)庫服務(wù)器(B) 主數(shù)據(jù)庫 IP:192.168.1.138
兩臺(tái)服務(wù)器同步的用戶名為: bravedu 密碼: brave123
一、主數(shù)據(jù)庫操作設(shè)置(A):
① 創(chuàng)建同步用戶名 允許連接的 用戶IP地址 (非本機(jī)IP)
grant replication slave on *.* to 'bravedu'@'192.168.1.%' identified by 'brave123';
flush privileges;
② 更改mysql配置文件
[mysqld]
server-id = 1
log-bin=/www/mysql/binlog/binlog (路徑要根據(jù)自己的安裝設(shè)置)
binlog-do-db = dbname (要同步的數(shù)據(jù)庫名)
binlog-ignore-db=mysql
#相對應(yīng)主從數(shù)據(jù)庫同步不同的地方
log-slave-updates
sync_binlog=1
auto_increment_offset=1
auto_increment_increment=2
replicate-do-db = dbname
replicate-ignore-db = mysql,information_schema
重啟mysql服務(wù)器
③ 查看主數(shù)據(jù)庫同步狀態(tài) IP: ***.134
mysql>flush tables with read lock;
mysql>show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001 (這里注意 設(shè)置從服務(wù)器的時(shí)候要用)
Position: 106 (這里注意設(shè)置從服務(wù)器的時(shí)候要用)
Binlog_Do_DB: dbname
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
mysql>unlock tables;
*****主服務(wù)器到目前位置設(shè)置完畢*******
二、從數(shù)據(jù)庫操作設(shè)置(B):
① 創(chuàng)建同步用戶名
grant replication slave on *.* to 'bravedu'@'192.168.1.%' identified by 'brave123';
flush privileges;
② 更改mysql配置文件
[mysqld]
server-id = 2
log-bin=/www/mysql/binlog/binlog (路徑要根據(jù)自己的安裝設(shè)置)
binlog-do-db = dbname (要同步的數(shù)據(jù)庫名)
binlog-ignore-db= mysql,information_schema
#相對于主從同步不同的地方
binlog-do-db = dbname
binlog-ignore-db=mysql
log-slave-updates
sync_binlog=1
auto_increment_offset=2
auto_increment_increment=2
重啟mysql服務(wù)器
查看主數(shù)據(jù)庫同步狀態(tài) IP: ***.138
mysql>flush tables with read lock;
mysql>show master status\G
*************************** 1. row ***************************
File: mysql-bin.000005 (這里注意 設(shè)置從服務(wù)器的時(shí)候要用)
Position: 106 (這里注意設(shè)置從服務(wù)器的時(shí)候要用)
Binlog_Do_DB: dbname
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
mysql>unlock tables;
③ 指定主主數(shù)據(jù)庫服務(wù)器同步指令
注:IP為主服務(wù)器的IP,用戶名,密碼,log_file,log_post 服務(wù)器互相統(tǒng)一
可能這塊操作 需要先 解除鎖表、停止數(shù)據(jù)庫狀態(tài)、在運(yùn)行后 在啟動(dòng)狀態(tài)
mysql > stop slave;
#設(shè)置192.168.1.138數(shù)據(jù)庫服務(wù)器配置 那么host 配置文件信息 就是 134的信息
mysql > change master to master_host='192.168.1.134', master_user='bravedu', master_password='brave123', master_log_file='mysql-bin.000005', master_log_pos=106;
#設(shè)置192.168.1.134 數(shù)據(jù)庫服務(wù)器配置 那么host 等配置文件信息 就是 134的信息
mysql > change master to master_host='192.168.1.138', master_user='bravedu', master_password='brave123', master_log_file='mysql-bin.000001', master_log_pos=106;
mysql > start slave;
mysql > unlock tables;
④ 查看主數(shù)據(jù)庫同步狀態(tài) 會(huì)出來很多信息 但是主要看這兩個(gè)狀態(tài)就行了 如果都是 yes 就可以了
mysql>show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
至此,主主數(shù)據(jù)庫同步成功配置完成。
- Linux下MySQL數(shù)據(jù)庫的主從同步復(fù)制配置
- MYSQL5.6.33數(shù)據(jù)庫主從(Master/Slave)同步安裝與配置詳解(Master-Linux Slave-windows7)
- Linux下rsync遠(yuǎn)程數(shù)據(jù)同步命令的詳細(xì)介紹
- linux下實(shí)現(xiàn)web數(shù)據(jù)同步的四種方式(性能比較)
- linux下指定mysql數(shù)據(jù)庫服務(wù)器主從同步的配置實(shí)例
- linux下mysql數(shù)據(jù)庫單向同步配置方法分享
- MySQL 數(shù)據(jù)庫兩臺(tái)主機(jī)同步實(shí)戰(zhàn)(linux)
- cwrsync實(shí)現(xiàn)從linux到windows的數(shù)據(jù)同步備份
- Linux下sersync數(shù)據(jù)實(shí)時(shí)同步
相關(guān)文章
MySQL?數(shù)據(jù)庫的基礎(chǔ)知識(shí)
這篇文章主要介紹了MySQL?數(shù)據(jù)庫的基礎(chǔ)知識(shí),它是一類更具體的可以管理數(shù)據(jù)的軟件。但是實(shí)現(xiàn)數(shù)據(jù)庫的這個(gè)軟件,需要用到很多的數(shù)據(jù)結(jié)構(gòu),下面來看看文章是怎么具體介紹這個(gè)數(shù)據(jù)庫的2021-12-12MySQL多個(gè)字段拼接去重的實(shí)現(xiàn)示例
在MySQL中,我們經(jīng)常會(huì)遇到需要將多個(gè)字段進(jìn)行拼接并去重的情況,本文就來介紹一下MySQL多個(gè)字段拼接去重的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01MySQL數(shù)據(jù)庫InnoDB數(shù)據(jù)恢復(fù)工具的使用小結(jié)詳解
本篇文章是對MySQL數(shù)據(jù)庫InnoDB數(shù)據(jù)恢復(fù)工具的使用進(jìn)行了詳細(xì)的總結(jié)與分析,需要的朋友參考下2013-06-06MySQL里的found_row()與row_count()的解釋及用法
MySQL中有兩個(gè)函數(shù)來計(jì)算上一條語句影響了多少行,不同于SqlServer/Oracle,不要因?yàn)榇朔矫娴牟町惗鸸δ軉栴}2013-02-02