MYSQL-Master-HA檢測主從複製狀態的時出現“User xxx does not exist or does not have REPLICATION SLAVE privilege”異常:
[root@mhamaster ~]# masterha_check_repl --conf=/etc/app1.cnf
Fri Sep 14 09:59:26 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Sep 14 09:59:26 2012 - [info] Reading application default configurations from /etc/app1.cnf..
Fri Sep 14 09:59:26 2012 - [info] Reading server configurations from /etc/app1.cnf..
Fri Sep 14 09:59:26 2012 - [info] MHA::MasterMonitor version 0.53.
Fri Sep 14 09:59:29 2012 - [info] Dead Servers:
Fri Sep 14 09:59:29 2012 - [info] Alive Servers:
Fri Sep 14 09:59:29 2012 - [info] 192.168.1.60(192.168.1.60:3306)
Fri Sep 14 09:59:29 2012 - [info] 192.168.1.61(192.168.1.61:3306)
Fri Sep 14 09:59:29 2012 - [info] 192.168.1.62(192.168.1.62:3306)
Fri Sep 14 09:59:29 2012 - [info] Alive Slaves:
Fri Sep 14 09:59:29 2012 - [info] 192.168.1.61(192.168.1.61:3306) Version=5.5.20-log (oldest major version between slaves) log-bin:enabled
Fri Sep 14 09:59:29 2012 - [info] Replicating from 192.168.1.60(192.168.1.60:3306)
Fri Sep 14 09:59:29 2012 - [info] Primary candidate for the new Master (candidate_master is set)
Fri Sep 14 09:59:29 2012 - [info] 192.168.1.62(192.168.1.62:3306) Version=5.5.20-log (oldest major version between slaves) log-bin:enabled
Fri Sep 14 09:59:29 2012 - [info] Replicating from 192.168.1.60(192.168.1.60:3306)
Fri Sep 14 09:59:29 2012 - [info] Not candidate for the new Master (no_master is set)
Fri Sep 14 09:59:29 2012 - [info] Current Alive Master: 192.168.1.60(192.168.1.60:3306)
Fri Sep 14 09:59:29 2012 - [info] Checking slave configurations..
Fri Sep 14 09:59:29 2012 - [info] read_only=1 is not set on slave 192.168.1.61(192.168.1.61:3306).
Fri Sep 14 09:59:29 2012 - [warning] relay_log_purge=0 is not set on slave 192.168.1.61(192.168.1.61:3306).
Fri Sep 14 09:59:29 2012 - [info] read_only=1 is not set on slave 192.168.1.62(192.168.1.62:3306).
Fri Sep 14 09:59:29 2012 - [warning] relay_log_purge=0 is not set on slave 192.168.1.62(192.168.1.62:3306).
Fri Sep 14 09:59:29 2012 - [info] Checking replication filtering settings..
Fri Sep 14 09:59:29 2012 - [info] binlog_do_db= , binlog_ignore_db=
Fri Sep 14 09:59:29 2012 - [info] Replication filtering check ok.
Fri Sep 14 09:59:29 2012 - [error][/usr/local/share/perl5/MHA/Server.pm, ln381] 192.168.1.61(192.168.1.61:3306): User repl does not exist or does not have REPLICATION SLAVE privilege! Other slaves can not start replication from this host.
Fri Sep 14 09:59:29 2012 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln383] Error happend on checking configurations. at /usr/local/share/perl5/MHA/ServerManager.pm line 1305
Fri Sep 14 09:59:29 2012 - [error][/usr/local/share/perl5/MHA/MasterMonitor.pm, ln478] Error happened on monitoring servers.
Fri Sep 14 09:59:29 2012 - [info] Got exit code 1 (Not master dead).
在MYSQL中我已經添加了repl複製帳號並給了權限了,但是爲何還報這個異常呢:
User repl does not exist or does not have REPLICATION SLAVE privilege! Other slaves can not start replication from this host.
很奇怪的問題。後來我又檢查了網絡、DNS、iptalbes等,各種配置也都沒問題。還按照一位兄弟分享出來解決各種MHA的問題(http://space.itpub.net/?uid-88305-action-viewspace-itemid-730836)的方式重新淘騰了一遍,還是無果。
後來,我就直接研究了MHA的源代碼,發現在Server.pm和DBHelper.pm兩個文件中的檢測過程都沒有問題...鬱悶了。後來我直接使用了:
Repl_User_SQL => "SELECT Repl_slave_priv AS Value FROM mysql.user WHERE user = ?";
在MYSQL上執行,問題出來了:
mysql> SELECT Repl_slave_priv AS Value FROM mysql.user WHERE user = 'repl';
+-------+
| Value |
+-------+
| N |
| Y |
+-------+
這裏爲何有兩個值呢?後來我又執行了一次:
mysql> SELECT user,host,password, Repl_slave_priv AS Value FROM mysql.user WHERE user = 'repl';
+-------+-------------+-------------------------------------------+-------+
| user | host | password | Value |
+-------+-------------+-------------------------------------------+-------+
| repl | % | *027*****6D8E759C6F4352B*********8465B8F8 | N |
| repl | 192.168.1.% | *027*****6D8E759C6F4352B*********8465B8F8 | Y |
+-------+-------------+-------------------------------------------+-------+
2 rows in set (0.00 sec)
一下我就明白了,原來我創建複製帳號的時候創建了兩個repl,而權限分配的不一樣。問題終於找到了。於是我把第一個刪掉,問題解決。