现在的位置: 首页 > 综合 > 正文

mysql 半同步(semi_sync)插件与skip-grant-tables冲突问题一例

2018年01月21日 ⁄ 综合 ⁄ 共 2533字 ⁄ 字号 评论关闭

今天一个朋友问说忘了mysqlroot密码怎么办,我告诉他重启的时候加--skip-grant-tables,然后update 密码之后flush privilges即可。

不过这哥们按照我说的做却直接报错如下:

 [root@hostxxx mysql-5.5.34-linux2.6-x86_64]# /etc/init.d/mysql3307 restart --skip-grant-tables  
   Shutting down MySQL.. SUCCESS! 
   Starting MySQL...... ERROR! The server quit without updating PID file (/data/mysql3307/mysql-5.5.34-linux2.6-x86_64/data/host132.pid).

查看错误日志发现:

   140306 14:13:40 [ERROR] /usr/sbin/mysqld: unknown variable 'rpl_semi_sync_master_enabled=1'
   140306 14:13:40 [ERROR] Aborting

哦,原来用到了半同步复制,第一个想法是去掉这个参数试试,又报其他版同步参数的错误,然后把所有版同步的参数都去掉,然后重启,嗷嗷的可以(泪奔)。

很显然这个不是因为mysql不认rpl_semi_sync_xxx参数的问题,这个必须和 --skip-grant-tables 选项有关。

顺道看了一下关于该参数的官方解释:

This option causes the server to start without using the privilege system at all, which gives anyone with access to the
server 
unrestricted
access to all databases
. You can cause a running server to start using the grant tables again by executing mysqladmin
flush-privileges
 or mysqladmin
reload
 command from a system shell, or by issuing a MySQLFLUSH
PRIVILEGES
 statement after connecting to the server.This option also suppresses loading
of plugins that were installed with the 
INSTALL
PLUGIN
 statement, user-defined functions (UDFs), and scheduled events.
To cause plugins to be loaded anyway,
use the 
--plugin-load option.

大概意思就是skip-grant-tables会在mysql启动的时候跳过所有的系统权限表,使得所有的用户都可以不用身份认证即可访问数据库。然后登录后(执行完各种操作比如更改密码等)可以执行flush
privileges来重新加载权限表(这样可以不用重启)。然而该参数会导致通过install plugin 语句加载的插件或UDFs(用户自定义外部函数区别于create function)以及调度事件(也就是job)等无法加载到mysql。

到这里也就能理解为啥报错了,plugin的信息存放在mysql.plugin下如:

(user:root  time: 16:53)[db: mysql]select * from mysql.plugin;
+----------------------+--------------------+
| name                 | dl                 |
+----------------------+--------------------+
| rpl_semi_sync_master | semisync_master.so |
| rpl_semi_sync_slave   | semisync_slave.so  |
+----------------------+--------------------+

skip-grant-tables
参数把mysql的系统表都给跳过了,自然mysql就不认识半同步的配置参数了。

那怎么个解决呢,顺其自然的想到了是不是有参数控制在跳过权限的时候依然(或者说任何时候)可以加载插件呢,嘿,这想法不错,然后就找找找

经过九九八十一难终于发现上面那段英文里的蓝色字体 --plugin-load  

意思是说想让plugin在任何时候都被mysql加载那么请用--plugin-load  用法如下:

[root@hostxxx mysql-5.5.34-linux2.6-x86_64]#
/etc/init.d/mysql3307 restart --skip-grant-tables --skip_slave_start  --plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so";
    Shutting down MySQL.. SUCCESS! 
 
  Starting MySQL.... SUCCESS! 

另外,如果嫌这种写法比较麻烦还可以放在my.cnf里[mysqld]下,多个.so
可使用;隔开

plugin-load="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"

一个小插曲,优雅又有趣!

参考:

http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_skip-grant-tables

http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_plugin-load

抱歉!评论已关闭.