The MySQL server is running with the --read-only option so it cannot execute this statement
正在開會,同事電話反映開發庫不能寫入了,錯誤信息如下:
1209 - The MySQL server is running with the--read-only option so it cannot execute this statement
一般這個錯誤有兩種原因:
1.連到從庫了。從庫一般設置為只讀。
2.主庫的read_only參數被修改為1
開發人員是普通用戶應該沒有權限修改這個參數的值。
DBA也不會去主動修改這個參數。那究竟是什么原因導致開發庫不能寫入了呢?
首先確認了不是開發人員的問題,因為部門的200多位研發都遇到了這個問題。
為了先解決問題,先去查詢主庫上read_only參數的值。果然read_only被設置為1.
手工修改為0后,問題解決。問題是read_only為什么會設置為1呢?
解決步驟如下:
mysql> select @@read_only;
+-------------+
| @@read_only |
+-------------+
| 1 |
+-------------+
1 row in set (0.00 sec)
mysql> set global read_only=0;
Query OK, 0 rows affected (0.00 sec)
檢查mysql的錯誤日志發現有如下信息:
151231 13:55:11 mysqld_safe Number ofprocesses running now: 0
151231 13:55:11 mysqld_safe mysqldrestarted
由此可知MySQL發生了重啟。重啟的原因是什么呢?
檢查了系統日志,發現了如下錯誤:
#tail -100f /var/log/message
Dec 31 13:55:11 mysql2dev kernel: [8680] 500 8680 27084 92 3 0 0 bash
Dec 31 13:55:11 mysql2dev kernel: Out ofmemory: Kill process 12805 (mysqld) score 964 or sacrifice child
Dec 31 13:55:11 mysql2dev kernel: Killedprocess 12805, UID 500, (mysqld) total-vm:13146848kB, anon-rss:7870704kB,file-rss:16kB
Dec 31 13:55:11 mysql2dev kernel: rsyslogdinvoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0
Dec 31 13:55:11 mysql2dev kernel: rsyslogdcpuset=/ mems_allowed=0-1
Dec 31 13:55:11 mysql2dev kernel: Pid:21035, comm: rsyslogd Not tainted 2.6.32-358.el6.x86_64 #1
Dec 31 13:55:11 mysql2dev kernel: CallTrace:
由這條錯誤可知,是由于內存溢出導致了mysql的重啟
Out of memory: Kill process 12805 (mysqld)score 964 or sacrifice child
那是什么導致了內存溢出呢?
查看了系統的歷史命令后發現有同事在做備份,而此時的系統的壓力又比較大,且次系統沒有設置交換分區,以上原因導致了MySQL的重啟。
Swap: 0 0 0
為什么重啟會導致read_only=1呢? 可能是配置文件中設置了read_only ,檢查配置文件
#grep read_only my.cnf
read_only = on
這時開發環境突然不能寫入的原因終于水落石出了。
你可能會問,主庫為什么設置read_only=on呢,因為原來是一個MMM環境。
現在已經把MMM環境摘掉,所以將配置文件中的read_only 設置為0,至此開發庫不能寫入問題宣告解決。
MySQL報錯:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement等問題
1.登錄的mysql:mysql ?u root ?p
mysql> set global read_only=0;(關掉新主庫的只讀屬性)
flush privileges;
2.修改mysql配置文件my.cnf,該文件在/etc目錄下
重啟mysql服務:service mysqld restart
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
在安裝Mysql8.0.3過程中重置密碼時報了這個錯誤, 原因是沒有設置密碼時需要在/etc/my.cnf中添加這段時才能操作mysql
#跳過密碼驗證
skip-grant-tables
但是添加完這句后操作mysql又報了這個錯誤, 這就成了一個死循環, 最后發現了解決辦法,
這是因為權限設置了但還沒有刷新導致的。
先執行
flush privileges;
再執行sql語句, 成功了
ALTER USER ’root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ’你的密碼’;
相關文章: