1. 程式人生 > >MYSQL主、從伺服器配置及錯誤處理

MYSQL主、從伺服器配置及錯誤處理

 一. MySQL主伺服器配置
1.建立使用者
grant replication slave on *.* to [email protected] identified by '123456';
# grant replication slave on *.* to ‘使用者名稱’@'主機’ identified by ‘密碼’;
# 可在B Slave上做連線測試: mysql -h 192.168.8.100 -ugd -p

2.編輯配置檔案/etc/my.cnf
# 確保有如下行
server-id = 1
log-bin=mysql-bin
binlog-do-db=test
binlog-ignore-db=mysql
#binlog-do-db=需要備份的資料庫名,可寫多行
#binlog-ignore-db=不需要備份的資料庫名,可寫多行




二.MySQL從伺服器配置
編輯/etc/my.cnf
server-id=2
log-bin=mysql-bin
master-host=192.168.6.100
master-user=gd
master-password=123456
master-port=3306
replicate-do-db=test
# replicate-do-db=test 需要備份的資料庫名
# replicate-ignore-db=mysql 忽略的資料庫
# master-connect-retry=60 如果從伺服器發現主伺服器斷掉,重新連線的時間差(秒)



修改配置需要注意,需要刪除從伺服器上的/var/lib/mysql/master.info檔案
[
[email protected]
~]# rm -f /var/lib/mysql/master.info
[[email protected] ~]# /etc/init.d/mysql restart


再次開啟/var/lib/mysql/master.info ,可以看到以下的資訊:
14

4
192.168.6.100
gd
123456
3306
60
0







在 192.168.6.101 上,用帳號 gd 登入,檢視 主伺服器的 狀態:
mysql> show master status;
ERROR 1227 (42000): Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation


在 192.168.6.100 上,給
[email protected]
分配許可權:
mysql> select * from mysql.user where user='gd';
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | gd | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
| 192.168.6.101 | gd | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+


mysql> grant super on *.* to
[email protected]
;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from mysql.user where user='gd';
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | gd | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
| 192.168.6.101 | gd | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | Y | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
+---------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+


在 192.168.6.101 上,用帳號 gd 登入,
檢視 主伺服器的 狀態:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000010 | 98 | test | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

檢視 從伺服器的 狀態:
mysql> show slave status;
Empty set (0.00 sec)


檢視 從伺服器的 狀態:
mysql> show slave hosts;
Empty set (0.00 sec)

從主伺服器讀取二進位制日誌。
mysql> show binlog events;
+------------------+-----+-------------+-----------+-------------+-------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+-----+-------------+-----------+-------------+-------------------------------------------------+
| mysql-bin.000001 | 4 | Format_desc | 1 | 98 | Server ver: 5.0.83-community-log, Binlog ver: 4 |
| mysql-bin.000001 | 98 | Stop | 1 | 117 | |
+------------------+-----+-------------+-----------+-------------+-------------------------------------------------+
2 rows in set (0.01 sec)



在 192.168.6.101 上,用帳號 root 登入,
檢視 從伺服器的 狀態:
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.6.100
Master_User: gd
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: CentOS-2-relay-bin.000022
Relay_Log_Pos: 98
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB: test,test1
Replicate_Ignore_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: 98
Relay_Log_Space: 98
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: NULL
1 row in set (0.00 sec)




SLAVE STOP IO_THREAD //此執行緒把master段的日誌寫到本地
mysql> slave stop IO_THREAD;
Query OK, 0 rows affected (0.00 sec)

SLAVE STOP SQL_THREAD //此執行緒把寫到本地的日誌應用於資料庫
mysql> slave stop sql_thread;
Query OK, 0 rows affected (0.00 sec)

執行完上面兩行之後,再次檢視狀態,注意以下兩行:
mysql> show slave status \G;
Slave_IO_State:
Slave_SQL_Running: No



------------------------------------------------------------------------------------------------------------------------------------














//
//
mysql> load data from master ;
ERROR 1218 (08S01): Error connecting to master: Lost connection to MySQL server at 'reading initial communication packet', system error: 113


mysql> slave stop;
Query OK, 0 rows affected (0.02 sec)

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n;
ERROR 1232 (42000): Incorrect argument type to variable 'sql_slave_skip_counter'

mysql> slave start;
Query OK, 0 rows affected (0.01 sec)

//







//
問題:
Slave_IO_Running: No
Slave_SQL_Running: Yes


解決方法:


登入master:
mysql> show master status \G
*************************** 1. row ***************************
File: mysql-bin.000067
Position: 106


登入slave:
mysql> slave stop;
mysql> change master to Master_Log_File='mysql-bin.000067',Master_Log_Pos=106;
mysql> start slave;


如果上面執行都正常的話,在slave上執行”show slave status \G”
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.199.199
Master_User: rep1
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000067
Read_Master_Log_Pos: 106
Relay_Log_File: newweb-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000067
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


//

相關推薦

MYSQL伺服器配置錯誤處理

 一. MySQL主伺服器配置 1.建立使用者 grant replication slave on *.* to [email protected] identified by '123456'; # grant replication slave on *.*

Apache 配置錯誤處理

第一步:Apache配置 下載Apache,並且配置。(下載地址:http://httpd.apache.org/download.cgi ) 配置教程: http://jing

MySQL主從(MySQL proxy Lua讀寫分離設置,一同步配置,分庫分表方案)

否則 count user username 2個 ons 基礎 zxvf 路徑 Mysql Proxy Lua讀寫分離設置一.讀寫分離說明讀寫分離(Read/Write Splitting),基本的原理是讓主數據庫處理事務性增、改、刪操作(INSERT、UPDATE、DE

011.MySQL+Keepalived配置

一 基礎環境 主機名 系統版本 MySQL版本

Redis 中哨兵sentinel 機制宕機恢復庫宕機恢復解決方案

目錄 什麼是哨兵 原理 環境 設定哨兵 從宕機及恢復 主宕機及恢復 配置多個哨兵 1、什麼是哨兵 哨兵是對Redis的系統的執行情況的監控,它是一個獨立程序,功能有二個: 監控主資料庫和從資料庫是否執行正常; 主資料出現故障後

搭建DNS伺服器,並實現智慧解析

1. 主、從DNS伺服器 主DNS伺服器:維護所負責解析的域的資料庫的伺服器;讀寫操作均可進行;主伺服器的資料會不斷髮生改變; 從DNS伺服器:從主DNS伺服器那裡或其它的從DNS伺服器那裡“複製”一份解析庫;但只能進行讀操作不能修改;從伺服器的資料庫要隨時同步主伺服器的資料; 2. 主、從

Spring 一 資料庫配置

一、新建jdbc.properties配置檔案 master.jdbc.driverClassName=com.mysql.jdbc.Drivermaster.jdbc.url=jdbc:mysql://127.0.0.1:3306/springdemo?useUnico

Linux下構建域名伺服器

實驗背景:       小諾公司目前搭建了郵件伺服器、web伺服器,現在需要使用Linux搭建一臺DNS伺服器為上面的服務提供域名解析,考慮到DNS伺服器的安全性,還需要搭建一臺從DNS伺服器。

protobuf安裝配置錯誤解決

protobuf配置:https://blog.csdn.net/u012477435/article/details/80765005 安裝錯誤解決:https://blog.csdn.net/legend18/article/details/49840607   配置步驟:

JBoss伺服器環境安裝與配置錯誤分析

壞境配置完成目錄如下: 注意:把JAVA_HOME變數名新增到path路徑中,新增格式如下: %JAVA_HOME%\bin;(;比不可少,是各個路徑之間的分隔符) 1.配置所需的壞境變數:(基於

MySQL建立雙向備複製伺服器配置方法

1、環境描述  伺服器A(主) 192.85.1.175   伺服器B(從) 192.85.1.176  Mysql版本:5.1.61        系統版本:System OS:ubuntu 10.10 X86 (系統安裝及資料環境搭建,省略) 2. 建立同步使用者: 在

Linux下mysql資料庫一同步配置

MySQL主從同步配置 mmj 16.09.29 1.確認執行環境 1.1確認主從IP 主伺服器(master):192.168.3.10 從伺服器(slave):192.168.3.18 1.2確認資料庫版本 都為5.5.31 2.主伺服器上配置 2.1修改MySQ

MySQL主從配置

準備:mysql安裝包:MySQL-5.6.rpm.tar5臺linux主機:Red Hat Enterprise Linux Server release 6.7 (Santiago)1、主機、IP清單[[email protected] ~]# vim /etc

centos7.x 部署DNS伺服器

1、準備 例:兩臺192.168.219.146(主), 192.168.219.147(從), 域名www.panyangduola.com 主、從DNS伺服器均需要安裝bind、bind-chroot、bind-utils yum -y install bind bind-utils bind-chroo

Linux—CentOS7.4-DNS二(搭建域名同步服務器)

roc 查看 update try gre 服務器驗證 .com entos centos7.4 環境:兩臺Linux服務器主服務器IP地址:192.168.80.10從服務器IP地址:192.168.80.20 第一步:主服務器配置[root@localhost ~]#

egrepbash環境配置腳本vim編輯器

系統 Linux egrep及擴展的正則表達式 egrep = grep -E egrep [options] pattern [file..] 擴展正則表達式的元字符字符匹配.:匹配任意單個字符[root@localhost ~]# grep -E . /tmp/123ABC123boy []:匹配

MySQL環境變量的配置說明

text f11 環境變量的配置 ext img serve 右鍵 系統設置 data 工具/原料 Windows操作系統 MySQL數據庫 方法/步驟 1 使用Win+R快捷鍵打開dos命令窗口,找到MySQL安裝目錄下的bi

Hibernate_day03---表與表關係建立一對多配置操作多對多配置操作

一、表與表關係建立思路 一對多關係 關係舉例: (1)分類和商品關係。 一個分類裡面有多個商品,一個商品只能屬於一個分類 (2)公司和員工關係 一個公司有多個員工,每個員工屬於一個公司 一對多建表:通過外來鍵建立關係 圖示: 多對多關係 關係舉例

MyEclipseEclipse使用配置部分問題

  簡單總結一下myeclipse首次使用的配置,eclipse類似。總結的不是很全面,如有新的看法,歡迎下方留言。 最優設定 1、myeclipse啟用 myeclipse、eclipse程式及啟用工具下載:點我 。啟用後檢視 myeclipse

redis 三安裝配置

1 下載redis3.2.9.tar.gz(官網下載) 2 解壓安裝 確保安裝gcc gcc-cc+,能夠使用make編譯 make make intall PREFIX=安裝路徑 3 安裝啟