Mysql 主從數(shù)據(jù)庫(kù)同步(centos篇)
環(huán)境:
配置:
添加
server-id=1
并開(kāi)啟log-bin二進(jìn)制日志文件
log-bin=mysql-bin
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.0000010 | 106| | |
+------------------+----------+--------------+------------------+
添加
server-id=2
-> master_host='192.168.1.22'
-> master_user='repl'
-> master_password='repl'
-> master_log_file='mysql-bin.0000010'
-> master_log_pos=106;
*************************** 2. row ***************************
Id: 2
User: system user
Host:
db: NULL
Command: Connect
Time: 2579
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.22
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.0000010
Read_Master_Log_Pos: 106
Relay_Log_File: centos-relay-bin.000002
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.0000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_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: 106
Relay_Log_Space: 830
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:
1 row in set (0.00 sec)
驗(yàn)證是否配置正確
Waiting for master to send event
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
測(cè)試
mysql>create table user(id int);
mysql> show tables like 'user';
+----------------------+
| Tables_in_test(user) |
+----------------------+
| user |
+----------------------+
1 row in set (0.00 sec)
問(wèn)題?
#binlog-ignore-db=不需要備份的數(shù)據(jù)庫(kù)名,可寫(xiě)多行
從服務(wù)器my.cnf
# replicate-ignore-db=mysql 忽略的數(shù)據(jù)庫(kù)
# master-connect-retry=60 如果從服務(wù)器發(fā)現(xiàn)主服務(wù)器斷掉,重新連接的時(shí)間差(秒)
master-host=192.168.1.22
master-port=3306
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.0000011 | 260| | |
+------------------+----------+--------------+------------------+
+--------------------------------------------------+
| master_pos_wait('mysql-bin.0000011','260') |
+--------------------------------------------------+
| 0 |
+--------------------------------------------------+
1 row in set (0.01 sec)
Query OK,0 affected (0.00 sec)
mysql>show processlist\G;
Id: 2
User: system user
Host:
db: NULL
Command: Connect
Time: 4757
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
Query OK,0 affected (0.00 sec)
mysql>reset master;
Query OK,0 affected (0.00 sec)
3、刪除新的主服務(wù)器數(shù)據(jù)庫(kù)目錄中的master.info和relay-log.info文件,否則下次重啟時(shí)還會(huì)按照從服務(wù)器來(lái)啟動(dòng).
相關(guān)文章
Mysql中文漢字轉(zhuǎn)拼音的實(shí)現(xiàn)(每個(gè)漢字轉(zhuǎn)換全拼)
這篇文章主要介紹了Mysql中文漢字轉(zhuǎn)拼音的實(shí)現(xiàn),并且每個(gè)漢字會(huì)轉(zhuǎn)換全拼,使用Mysql自定義函數(shù)實(shí)現(xiàn),需要的朋友可以參考下2014-06-06mysql觸發(fā)器簡(jiǎn)介、創(chuàng)建觸發(fā)器及使用限制分析
這篇文章主要介紹了mysql觸發(fā)器簡(jiǎn)介、創(chuàng)建觸發(fā)器及使用限制,結(jié)合實(shí)例形式分析了mysql觸發(fā)器的功能、原理、創(chuàng)建、用法及操作注意事項(xiàng),需要的朋友可以參考下2019-12-12安裝MySQL時(shí),輸入mysqld --install后,顯式該文件已存在問(wèn)題
這篇文章主要介紹了安裝MySQL時(shí),輸入mysqld --install后,顯式該文件已存在問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12Linux下安裝Mysql多實(shí)例作為數(shù)據(jù)備份服務(wù)器實(shí)現(xiàn)多主到一從多實(shí)例的備份
由于第一次接觸LINUX,花了三天時(shí)間才算有所成就,發(fā)出來(lái)希望可以給大伙帶來(lái)方便2010-07-07MySQL中json_extract函數(shù)說(shuō)明及使用方式
今天看mysql中的json數(shù)據(jù)類型,涉及到一些使用,使用到了函數(shù)json_extract來(lái),下面這篇文章主要給大家介紹了關(guān)于MySQL中json_extract函數(shù)說(shuō)明及使用方式的相關(guān)資料,需要的朋友可以參考下2022-08-08mysql之跨庫(kù)關(guān)聯(lián)查詢(dblink)問(wèn)題
這篇文章主要介紹了mysql之跨庫(kù)關(guān)聯(lián)查詢(dblink)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03