好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)

MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)

熱門標簽:地圖簡圖標注 如何選擇優質的外呼系統 清遠申請400電話 東莞外呼企業管理系統 南通電銷外呼系統哪家強 手機外呼系統違法嗎 谷歌地圖標注位置圖解 沈陽智能外呼系統供應商 桂林云電銷機器人收費

MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)
本篇文章主要介紹了MySQL5.6 數據庫主從同步安裝與配置詳解,具有一定的參考價值,有興趣的可以了解一下。
安裝環境

操作系統 :CentOS 6.5

數據庫版本:MySQL 5.6.27

主機A:192.168.1.1 (Master)

主機B:192.168.1.2 (Slave)

這里強調的數據庫的版本,是因為MySQL在5.6之前和之后的安裝方式是不一樣的。

本人在進行配置的時候,也遇到了這個坑,這里提前說明,希望大家不要采坑。

注:這里有一篇CentOS安裝MySQL的文章,在這里引出,過程親測,希望對大家有幫助:https://www.jb51.net/article/101778.htm

基本環境配置

首先,要保證防火墻對3306端口的開啟,如果只是為了學習數據庫的主從配置,可以使用service iptables stop 命令直接關閉防火墻。

然后可以在兩臺機子之間進行 ping操作,確保兩臺機器之間能夠相同。

Master的配置

在Linux環境下MySQL的配置文件的位置是在 /etc/my.cnf ,在該文件下指定Master的配置如下:

log-bin=mysql-bin
server-id=2
binlog-ignore-db=information_schema
binlog-ignore-db=cluster
binlog-ignore-db=mysql
binlog-do-db=ufind_db 

這里的server-id用于標識唯一的數據庫,這里設置為2,在設置從庫的時候就需要設置為其他值。

binlog-ignore-db:表示同步的時候ignore的數據庫

binlog-do-db:指定需要同步的數據庫

完整配置截圖如下:

1、然后重啟mysql:

service mysqld restart

2、進入mysql:[root@VM_221_4_centos ~]# mysql -u root -p 回車,輸入mysql密碼進入。

3、 賦予從庫權限帳號,允許用戶在主庫上讀取日志,賦予192.168.1.2也就是Slave機器有File權限,只賦予Slave機器有File權限還不行,還要給它REPLICATION SLAVE的權限才可以。

在Master數據庫命令行中輸入:

 >GRANT FILE ON *.* TO 'root'@'192.168.1.2' IDENTIFIED BY 'mysql password';

 >GRANT REPLICATION SLAVE ON *.* TO 'root'@'192.168.1.2' IDENTIFIED BY 'mysql password';
>FLUSH PRIVILEGES

這里使用的仍是 root 用戶作為同步的時候使用到的用戶,可以自己設定。

4、重啟mysql,登錄mysql,顯示主庫信息

mysql> show master status;
mysql> show master status;
+------------------+----------+--------------+----------------------------------+-------------------+
| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000004 |  28125 | ufind_db   | information_schema,cluster,mysql |          |
+------------------+----------+--------------+----------------------------------+-------------------+
1 row in set (0.00 sec)

mysql> 

這里的 File 、Position 是在配置Salve的時候要使用到的,Binlog_Do_DB表示要同步的數據庫,Binlog_Ignore_DB 表示Ignore的數據庫,這些都是在配置的時候進行指定的。

另外:如果執行這個步驟始終為Empty set(0.00 sec),那說明前面的my.cnf沒配置對。

Slave的配置

1、從庫的配置,首先也是修改配置文件:/etc/my.cnf 如下:

log-bin=mysql-bin
server-id=3
binlog-ignore-db=information_schema
binlog-ignore-db=cluster
binlog-ignore-db=mysql
replicate-do-db=ufind_db
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60

2、這里可以看到,在MySQL5.6之后的版本中沒有指定:

master-host=192.168.1.1 #Master的主機IP
master-user=root
master-password=mysql password #Master的MySQL密碼

3、這也是在網上很多搜索的配置過程,他們也都指定了數據庫的版本,但是并沒有說出來新版本的配置這種方式是不適用的。

4、如果,你在MySQL5.6和之后的版本中配置從庫的時候,設置到了上邊的內容,即指定了master-host、master-user等信息的話,重啟MySQL的時候就回報錯,錯誤信息如下:

[root@VM_128_194_centos bin]# service mysqld restart
Shutting down MySQL... SUCCESS! 
Starting MySQL... ERROR! The server quit without updating PID file (/data/mysqldb/VM_128_194_centos.pid).
[root@VM_128_194_centos bin]# 

此時,查看數據庫的報錯信息(數據庫的目錄, /data/mysqldb/VM_128_194_centos.err ),可以看到:

2016-05-06 13:12:04 13345 [Note] InnoDB: Waiting for purge to start
2016-05-06 13:12:04 13345 [Note] InnoDB: 5.6.27 started; log sequence number 2850211
2016-05-06 13:12:04 13345 [ERROR] /data/home/server/mysql-5.6.27/bin/mysqld: unknown variable 'master-host=192.168.1.1'
2016-05-06 13:12:04 13345 [ERROR] Aborting

可以看出master-host 被檢測數是一個未知的變量,因此會出現錯誤。

5、在5.6以及后續版本的配置如下:

修改完/etc/my.cnf 文件之后,重啟一下MySQL(service mysqld restart)

進入Slave mysql控制臺,執行:

mysql> stop slave; #關閉Slave
mysql> change master to master_host='192.168.1.1',master_user='root',master_password='123456',master_log_file='mysql-bin.000004', master_log_pos=28125;

mysql> start slave; #開啟Slave

在這里指定Master的信息,master_log_file是在配置Master的時候的File選項, master_log_pos是在配置Master的Position 選項,這里要進行對應。

然后可以通過mysql> show slave status; 查看配置的信息:

mysql> show slave status \G;
*************************** 1. row ***************************
        Slave_IO_State: Waiting for master to send event
         Master_Host: 192.167.1.1
         Master_User: root
         Master_Port: 3306
        Connect_Retry: 60
       Master_Log_File: mysql-bin.000004
     Read_Master_Log_Pos: 28125
        Relay_Log_File: VM_128_194_centos-relay-bin.000004
        Relay_Log_Pos: 26111
    Relay_Master_Log_File: mysql-bin.000004
       Slave_IO_Running: Yes
      Slave_SQL_Running: Yes
       Replicate_Do_DB: ufind_db
     Replicate_Ignore_DB: mysql
      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: 28125
       Relay_Log_Space: 26296
       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: 
 Replicate_Ignore_Server_Ids: 
       Master_Server_Id: 2
         Master_UUID: 8ac3066a-9680-11e5-a2ec-5254007529fd
       Master_Info_File: /data/mysqldb/master.info
          SQL_Delay: 0
     SQL_Remaining_Delay: NULL
   Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
      Master_Retry_Count: 86400
         Master_Bind: 
   Last_IO_Error_Timestamp: 
   Last_SQL_Error_Timestamp: 
        Master_SSL_Crl: 
      Master_SSL_Crlpath: 
      Retrieved_Gtid_Set: 
      Executed_Gtid_Set: 
        Auto_Position: 0
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql> 

可以看到,已經配置成功。

添加需要同步的從庫Slave

由于種種原因,測試的時候使用test庫,這里我按照上述的方式,修改Master的my.cnf的配置文件,新增同步的數據庫test,重啟MySQL,執行Master的:show master status如下:

相應的,要修改Slave從庫的信息在my.cnf 增加 replicate-do-db=test,重啟Mysql,根據上述的show master status,在Slave從庫中執行下邊的內容:

>stop slave
>change master to master_host='192.168.1.1',master_user='root',master_password='123456',master_log_file='mysql-bin.000005', master_log_pos=120;
>start slave

然后使用:show slave status;

mysql> show slave status\G;
*************************** 1. row ***************************
        Slave_IO_State: Waiting for master to send event
         Master_Host: 192.168.1.1
         Master_User: root
         Master_Port: 3306
        Connect_Retry: 60
       Master_Log_File: mysql-bin.000005
     Read_Master_Log_Pos: 1422
        Relay_Log_File: VM_128_194_centos-relay-bin.000004
        Relay_Log_Pos: 283
    Relay_Master_Log_File: mysql-bin.000005
       Slave_IO_Running: Yes
      Slave_SQL_Running: Yes
       Replicate_Do_DB: ufind_db,test
     Replicate_Ignore_DB: mysql
      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: 1422
       Relay_Log_Space: 468
       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: 
 Replicate_Ignore_Server_Ids: 
       Master_Server_Id: 2
         Master_UUID: 8ac3066a-9680-11e5-a2ec-5254007529fd
       Master_Info_File: /data/mysqldb/master.info
          SQL_Delay: 0
     SQL_Remaining_Delay: NULL
   Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
      Master_Retry_Count: 86400
         Master_Bind: 
   Last_IO_Error_Timestamp: 
   Last_SQL_Error_Timestamp: 
        Master_SSL_Crl: 
      Master_SSL_Crlpath: 
      Retrieved_Gtid_Set: 
      Executed_Gtid_Set: 
        Auto_Position: 0
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql> 

已經新增加了test。

真正的測試

在主庫中新增數據庫表,user,觀察從庫變化如下:

創建數據庫的時候:

新增數據的時候:

刪除Master數據庫表的時候:

配置過程,到此為止,希望能夠幫助大家,如有疑問 歡迎留言。也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • mysql同步問題之Slave延遲很大優化方法
  • 解決MySQL中的Slave延遲問題的基本教程
  • MySQL中slave監控的延遲情況分析
  • mysql 主從數據不一致,提示: Slave_SQL_Running: No 的解決方法
  • 記一次MySQL Slave庫恢復實戰記錄
  • Mysql主從數據庫(Master/Slave)同步配置與常見錯誤
  • MySQL中slave_exec_mode參數詳解
  • MySQL Slave 觸發 oom-killer解決方法
  • MySQL slave 延遲一列 外鍵檢查和自增加鎖

標簽:貴州 湖州 重慶 天津 臨沂 內蒙古 成都 常德

巨人網絡通訊聲明:本文標題《MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)》,本文關鍵詞  MySQL5.6,數據庫,主從,同步,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)》相關的同類信息!
  • 本頁收集關于MySQL5.6 數據庫主從同步安裝與配置詳解(Master/Slave)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 欧美成狂野欧美在线观看| 日本大尺度吃奶做爰电影叫啥| 七月婷婷在线网址| 乡村孽情| 双性人妻挨脔日常h| H高潮抽搐喷潮撒尿bl| free hd xxxx movies 动漫| 99精品在线看| 感觉男人下面好硬蹭的我下面疼 | 嗯啊好舒服| 2021韩国理伦片在线观看| 亚洲狠狠ady亚洲精品大秀| 国内精品综合久久久40p| 美女扒开尿口给男人桶爽视频| 巜痴汉电车强制肉欲BD| 色狠狠躁日日躁夜夜躁A一牛| 男女爱啪视频在线| 羞羞视频网站| 中文字幕精品1在线| 刘玥AV无码专区88| 波多野结衣两女调教一男| 10周岁女全身裸无遮挡| 色戒1080p| 337p粉嫩日本欧洲亚洲Av| 男生机机桶女生| 免费追剧软件全免费| 怎样免费观看日本综艺| 伊人久久大香色综合久久五月色| 国产精品aⅴ久久久久久鸭绿欲| 最新日韩伦理片免费| 欧美日韩一区二区三区视视频| a及毛片| 浴室里强摁做开腿呻吟快新车文| 奇米777狠狠狠888俺去也| 十八禁??国产污污的游戏合集| 男男插视频| 1000款最新夜间禁用软件app| 校花尿憋不住从小内内尿出来| 久久久久久精品免费观看| 出轨nph| 日本高清免费不卡在线|