国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql主從同步配置與不同步問題整理

2024-07-24 12:38:42
字體:
來源:轉載
供稿:網友

本文章詳細的介紹了mysql主從同步配置,包括了linux和windows中的主從配置及可能出現問題的解決辦法.

linux中主從同步

主服務器IP:250.110.120.119

從服務器IP:110.120.119.250

1.在主服務器新建一個用戶,給從服務器同步使用,代碼如下:

GRANT ALL PRIVILEGES ON *.* TO 'tongbu'@'110.120.119.250.' IDENTIFIED BY 'tongbu';意思是新建一個用戶名為tongbu 密碼為tongbu 具有所有操作權限的帳號.

2.修改主服務器my.cnf文件

其實這一步可以省略,因為保持默認的配置文件就可以了.

添加:server-id=1

并開啟log-bin二進制日志文件:log-bin=mysql-bin

注:需要把默認的server-id=1去掉

3.重啟主服務器mysql數據庫

4.進入mysql界面執行下面命令,獲取日志文件名和偏移量,代碼如下:

show master status;

顯示如:

  1. mysql> show master status; 
  2. +——————+———-+————–+——————+ 
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | 
  4. +——————+———-+————–+——————+ 
  5. | mysql-bin.000010 | 106 | | | 
  6. +——————+———-+————–+——————+ 
  7. 1 row in set (0.00 sec) 

得到的日志文件名為 mysql-bin.000010 偏移量為106.

5.修改從服務器的my.cnf.

添加一個:server-id=2

注:需要把默認的server-id=1去掉.

6.重啟從服務器mysql數據庫

7.對從數據庫進行設置,@@@這是最最重要的地方,代碼如下:

  1. change master to master_host='250.110.120.119', master_user='tongbu', master_password='tongbu', master_log_file='mysql-bin.000010', master_log_pos=106; 

8.啟動從服務器:start slave;

9.執行下面命令,查看進程:show processlistG

顯示如下,代碼如下:

  1. mysql> show processlistG 
  2. *************************** 1. row *************************** 
  3. Id: 4 
  4. User: root 
  5. Host: localhost 
  6. db: test 
  7. Command: Query 
  8. Time: 0 
  9. State: NULL 
  10. Info: show processlist 
  11. *************************** 2. row *************************** 
  12. Id: 5 
  13. User: system user 
  14. Host: 
  15. db: NULL 
  16. Command: Connect 
  17. Time: 1773 
  18. State: Waiting for master to send event 
  19. Info: NULL 
  20. *************************** 3. row *************************** 
  21. Id: 6 
  22. User: system user 
  23. Host: 
  24. db: NULL 
  25. Command: Connect 
  26. Time: 1630 
  27. State: Has read all relay log; waiting for the slave I/O thread to update it  --Vevb.com 
  28. Info: NULL 
  29. rows in set (0.00 sec) 

10.查看從服務器狀態,代碼如下:

show slave statusG

顯示如下:

  1. mysql> show slave statusG 
  2. *************************** 1. row *************************** 
  3. Slave_IO_State: Waiting for master to send event 
  4. Master_Host: 250.110.120.119 
  5. Master_User: tongbu 
  6. Master_Port: 3306 
  7. Connect_Retry: 60 
  8. Master_Log_File: mysql-bin.000010 
  9. Read_Master_Log_Pos: 281 
  10. Relay_Log_File: up2-relay-bin.000002 
  11. Relay_Log_Pos: 426 
  12. Relay_Master_Log_File: mysql-bin.000010 
  13. Slave_IO_Running: Yes 
  14. Slave_SQL_Running: Yes 
  15. Replicate_Do_DB: 
  16. Replicate_Ignore_DB: 
  17. Replicate_Do_Table: 
  18. Replicate_Ignore_Table: 
  19. Replicate_Wild_Do_Table: 
  20. Replicate_Wild_Ignore_Table: 
  21. Last_Errno: 0 
  22. Last_Error: 
  23. Skip_Counter: 0 
  24. Exec_Master_Log_Pos: 281 
  25. Relay_Log_Space: 579 
  26. Until_Condition: None 
  27. Until_Log_File: 
  28. Until_Log_Pos: 0 
  29. Master_SSL_Allowed: No 
  30. Master_SSL_CA_File: 
  31. Master_SSL_CA_Path: 
  32. Master_SSL_Cert: 
  33. Master_SSL_Cipher: 
  34. Master_SSL_Key: 
  35. Seconds_Behind_Master: 0 
  36. Master_SSL_Verify_Server_Cert: No 
  37. Last_IO_Errno: 0 
  38. Last_IO_Error: 
  39. Last_SQL_Errno: 0 
  40. Last_SQL_Error: 
  41. 1 row in set (0.00 sec) 

測試:

1、在主服務器test數據庫中創建user表,代碼如下:

  1. mysql>use test; 
  2. mysql>create table user(id int); 

2、在從服務器中查看user表,代碼如下:

  1. mysql>use test; 
  2. mysql> show tables like ‘user’; 
  3. +———————-+ 
  4. | Tables_in_test(user) | 
  5. +———————-+ 
  6. user | 
  7. +———————-+ 
  8. 1 row in set (0.00 sec) 

說明主從數據同步成功.

windows主從同步操作方案

負責在主、從服務器傳輸各種修改動作的媒介是主服務器的二進制變更日志,這個日志記載著需要傳輸給從服務器的各種修改動作,因此,主服務器必須激活二進制 日志功能,從服務器必須具備足以讓它連接主服務器并請求主服務器把二進制變更日志傳輸給它的權限.

環境:

A、B的MySQL數據庫版本同為5.0.18

A:操作系統:Windows 2003 IP地址:10.100.0.100

B:操作系統:Windows 2000 server 的IP地址:10.100.0.200

配置過程:

1、在A的數據庫中建立一個備份帳戶,命令如下:

  1. GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.*  
  2. TO backup@’10.100.0.200’  
  3. IDENTIFIED BY ‘1234’; 

建立一個帳 戶backup,并且只能允許從10.100.0.200這個地址上來登陸,密碼是1234.

2、因為 mysql版本新密碼算法不同,所以進入mysql下,輸入:

set password for'backup'@'10.100.0.200'=old_password('1234');

3、關停A服務器,將A中的數據拷貝到B服務器中,使得A和B中的數據同步,并且確保在全部設置操作結束前,禁止在A和B服務器中進行寫操作,使得兩數據 庫中的數據一定要相同!

4、對A服 務器的配置進行修改,打開mysql/my.ini文件,在[mysqld]下面添加如下內容:

  1. server-id=1 
  2. log-bin=c:log-bin.log 
  3. server- id:為主服務器A的ID值 
  4. log-bin:二進制變更日值 

4、重啟A 服務器,從現在起,它將把客戶堆有關數據庫的修改記載到二進制變更日志里去.

5、關停B 服務器,對B服務器錦熙配置,以便讓它知道自己的鏡像ID、到哪里去找主服務器以及如何去連接服務器,最簡單的情況是主、從服務器分別運行在不同的主機上 并都使用著默認的TCP/IP端口,只要在從服務器啟動時去讀取的mysql/my.ini文件里添加以下幾行指令就行了.

  1. [mysqld] 
  2. server-id=2 
  3. master-host=10.100.0.100 
  4. master-user=backup 
  5. master-password=1234 

以下內容為可選:

replicate-do-db=backup

server- id:從服務器B的ID值,注意不能和主服務器的ID值相同.

master-host:主服務器的IP地址.

master-user:從服務器連接主服務器的帳號.

master-password:從服務器連接主服務器的帳號密碼.

replicate-do-db:告訴主服務器只對指定的數據庫進行同步鏡像.

6、重啟從 服務器B,至此所有設置全部完成,更新A中的數據,B中也會立刻進行同步更新,如果從服務器沒有進行同步更新,你可以通過查看從服務器中的 mysql_error.log日志文件進行排錯.

8、查看日志一些命令:

1, show master statusG;在這里主要是看log-bin的文件是否相同。

show slave statusG;在這里主要是看:

Slave_IO_Running=Yes

Slave_SQL_Running=Yes

如果都是Yes,則說明配置成功.

2,在 master上輸入show processlistG;代碼如下:

  1. mysql> SHOW PROCESSLISTG 
  2.  *************************** 1. row *************************** 
  3.    Id: 2 
  4.    User: root 
  5.    Host: localhost:32931 
  6.    db: NULL 
  7.    Command: Binlog Dump 
  8.    Time: 94 
  9.    State: Has sent all binlog to slave; waiting for binlog to 
  10.      be updated 
  11.    Info: NULL 

如果出現Command: Binlog Dump,則說明配置成功.

MySQL主從不同步問題解決

1.首先停掉Slave服務:mysql> slave stop2.到主服務器上查看主機狀態,記錄File和Position對應的值,代碼如下:

  1. mysql> show master status; 
  2. +------------------+-----------+--------------+------------------+ 
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | 
  4. +------------------+-----------+--------------+------------------+ 
  5. | mysql-bin.000020 | 135617781 | | | 
  6. +------------------+-----------+--------------+------------------+ 
  7. 1 row in set (0.00 sec)3.到slave服務器上執行手動同步: 
  8. mysql> change master to 
  9. > master_host='master_ip'
  10. > master_user='user'
  11. > master_password='pwd'
  12. > master_port=3307, 
  13. > master_log_file='mysql-bin.000020'
  14. > master_log_pos=135617781; 
  15. 1 row in set (0.00 sec) 
  16. mysql> slave start;  --Vevb.com 
  17. 1 row in set (0.00 sec)再次查看slave狀態發現: 
  18. Slave_IO_Running: Yes 
  19. Slave_SQL_Running: Yes 

Seconds_Behind_Master: 0我們知道,因為DATA REPLICATION機制完全是基于在主上執行的增量SQL要被傳播到輔服務器上,并且被成功運行,這就勢必要求:在運行此機制前,主輔數據庫中數據是一致的,以及在運行此機制中,輔數據庫禁止來自其他的SQL(非主上傳播過來SQL)的寫操作,但是在運行中仍然可能遇到不一致的產生,這會導致通信無法正常繼續下去,因此一旦主從出現問題,首先應該解決同步位置的問題,修復丟失的數據.

MySQL主從不同步問題解決

問題 描述:主從復制在某個時刻,從服務器同步失敗,并給出報錯消息.

消息內容:基本意思是缺少某個庫的某個表.

原因:主從服務長時間不同步,主庫已經生成很多新的表或者庫,而從庫卻沒有.

操作過程:

1)登陸主服務器,查看主服務器的狀態Lmysql>show master status;

2)登陸從服務器,執行同步操作,代碼如下:

mysql>stop slave;mysql > change master to ...(此處省略);mysql > start slave;

3)從服務器上查看狀態,代碼如下:

mysql > show slave statusG

看報錯信息少什么表或庫,少什么就直接從主服務器通過scp復制,然后重復過程.

1)~3)直到不報錯為止.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上林县| 关岭| 花莲县| 东乡县| 商都县| 房产| 双流县| 天镇县| 龙海市| 伊川县| 长葛市| 襄城县| 调兵山市| 双峰县| 武宁县| 阿勒泰市| 玉田县| 镇雄县| 即墨市| 白山市| 汉寿县| 哈巴河县| 和政县| 邯郸市| 博乐市| 铅山县| 乾安县| 靖州| 平凉市| 永德县| 余江县| 岳普湖县| 韶关市| 都兰县| 南通市| 南康市| 乌兰察布市| 城步| 罗田县| 罗田县| 日照市|