環(huán)境:
AWS的MySQL數(shù)據(jù)庫(kù)集群服務(wù)
問(wèn)題描述:
MySQL數(shù)據(jù)庫(kù)的master數(shù)據(jù)庫(kù),某天忽然變得沒(méi)有寫權(quán)限了,爆出如下錯(cuò)誤:
### Cause: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement
; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1290]; The MySQL server is running with the --read-only option so it cannot execute this statement; nested exception is java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement
問(wèn)題分析:
查看數(shù)據(jù)庫(kù)讀寫權(quán)限情況:
show global variables like "%read_only%"
結(jié)果如下:

innodb read only?
啟動(dòng)server 在read-only模式。對(duì)于分布在數(shù)據(jù)庫(kù)應(yīng)用或者數(shù)據(jù)設(shè)置為只讀介質(zhì)。
innodb read only?為 on, 數(shù)據(jù)庫(kù)為完全只讀,任何用戶都無(wú)法寫數(shù)據(jù)。
如果是super privilege用戶設(shè)定的話,一般會(huì)設(shè)定read only的值,這樣的情況下,super privilege用戶還可以寫數(shù)據(jù)。
問(wèn)題原因:
1,AWS?RDS提供了主從自動(dòng)切換的功能,主數(shù)據(jù)庫(kù)崩潰后,從數(shù)據(jù)庫(kù)會(huì)自動(dòng)選出合適的一個(gè)充當(dāng)主庫(kù)。2,項(xiàng)目沒(méi)有使用RDS提供的集群讀寫proxy地址,而是使用了mysql實(shí)例的服務(wù)器地址,于是在主從自動(dòng)切換后,指向了錯(cuò)誤的讀寫服務(wù)器。
這又一個(gè)蠢到家的問(wèn)題!?。?/p>