今天一個朋友問說忘了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
statement after connecting to the server.This option also suppresses loading
PRIVILEGES
of plugins that were installed with the INSTALL
statement, user-defined functions (UDFs), and scheduled events.
PLUGIN
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