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 '你的密碼';