MySQL重啟之后無(wú)法寫入數(shù)據(jù)的問題排查及解決
背景
客戶在給系統(tǒng)打補(bǔ)丁之后需要重啟服務(wù)器,數(shù)據(jù)庫(kù)在重啟之后,read_only 的設(shè)置與標(biāo)準(zhǔn)配置 文件中不一致,導(dǎo)致主庫(kù)在啟動(dòng)之后無(wú)法按照預(yù)期寫入。
已知并沒有外部程序會(huì)對(duì)數(shù)據(jù)庫(kù)做只讀的設(shè)置,那么會(huì)是哪里出了問題?
排查過程
首先,檢查啟動(dòng)進(jìn)程配置文件的內(nèi)容,是否的確正確配置了 read_only ,有沒有在重啟前后對(duì)文件進(jìn)行修改:
# 檢查配置文件的修改狀態(tài) [root@localhost ~]# stat /usr/local/mysql/etc/my.cnf File: ‘/usr/local/mysql/etc/my.cnf' Size: 6160 Blocks: 16 IO Block: 4096 regular file Device: fd00h/64768d Inode: 591296 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 27/ mysql) Gid: ( 27/ mysql) Access: 2023-12-18 03:47:45.375190686 +0800 Modify: 2022-08-01 23:25:34.861953062 +0800 Change: 2022-08-01 23:25:34.862953087 +0800 Birth: - # 查看配置文件內(nèi)對(duì)read_only的設(shè)置 [root@localhost ~]# cat /usr/local/mysql/etc/my.cnf |grep read_only [root@localhost ~]# [root@localhost ~]#
已知數(shù)據(jù)庫(kù)版本信息為 8.0.25 ,近期沒有修改過配置文件,文件也沒有對(duì) read_only 進(jìn)行配置,默認(rèn)配置為 OFF :
其次,查看所有可能讀取的配置文件,并逐個(gè)排查:
# 1. 查看 mysql 配置文件默認(rèn)的加載順序 [root@localhost ~]# mysql --verbose --help | grep -A 1 'Default options' Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf # 2. 依次查看可能會(huì)存在的配置文件,及其配置的 read_only 值 [root@localhost ~]# ll /etc/my.cnf ls: cannot access /etc/my.cnf: No such file or directory [root@localhost ~]# ll /etc/mysql/my.cnf ls: cannot access /etc/mysql/my.cnf: No such file or directory # /usr/local/mysql/etc/my.cnf 為本實(shí)例啟動(dòng)時(shí)的指定配置文件,配置見上文,此處略 [root@localhost ~]# ll ~/.my.cnf -r-------- 1 root root 355 Aug 19 2021 /root/.my.cnf [root@localhost ~]# cat .my.cnf |grep read_only [root@localhost ~]# [root@localhost ~]# ll /home/mysql/.my.cnf ls: cannot access /etc/my.cnf: No such file or directory # 3. 通過檢查服務(wù)器上可能存在的配置文件,發(fā)現(xiàn) read_only 的設(shè)置在以上文件內(nèi)并不存在
以上查看配置文件 的配置并沒有找到相關(guān)配置,那么還有什么辦法呢?嘗試看看對(duì)數(shù)據(jù)庫(kù)的歷史操作記錄,確認(rèn)是否有用戶對(duì)數(shù)據(jù)庫(kù)做過 read_only 配置的操作:
# 通過 /root/.mysql_history ,看到這樣的歷史記錄: set PERSIST_ONLY read_only = 1;
全局模糊搜索配置文件,發(fā)現(xiàn)了 mysqld-auto.cnf
文件:
[root@localhost ~]# find / -name '*my*cnf' /root/my.cnf /root/.my.cnf /usr/share/mysql/README.mysql-cnf /usr/share/mysql/my-huge.cnf /usr/share/mysql/my-innodb-heavy-4G.cnf /usr/share/mysql/my-large.cnf /usr/share/mysql/my-medium.cnf /usr/share/mysql/my-small.cnf /usr/local/mysql/support-files/my.cnf /usr/local/mysql/etc/my.cnf /data/mysql/mysqld-auto.cnf # 查看 mysqld-auto.cnf 文件內(nèi)容,以及文件的操作時(shí)間 [root@localhost ~]# cat /data/mysql/mysqld-auto.cnf { "Version" : 1 , "mysql_server" : { "read_only" : { "Value" : "ON" , "Metadata" : { "Timestamp" : 1659045255269856 , "User" : "root" , "Host" : "localhost" } } } } # 時(shí)間戳轉(zhuǎn)換為北京時(shí)間 【1659045255269856】 -- >【2022-07-29 05:54:15】 # 查看 mysqld-auto.cnf 文件的狀態(tài) [root@localhost ~]# stat /data/mysql/mysqld-auto.cnf File: ‘/data/mysql/mysqld-auto.cnf' Size: 164 Blocks: 8 IO Block: 4096 regular file Device: fd08h/64776d Inode: 6291467 Links: 1 Access: (0640/-rw-r-----) Uid: ( 27/ mysql) Gid: ( 27/ mysql) Access: 2023-12-19 11:48:42.511662204 +0800 Modify: 2022-07-29 05:54:15.269682214 +0800 Change: 2022-07-29 05:54:15.269682214 +0800 Birth: -
這套數(shù)據(jù)庫(kù)之前由別的團(tuán)隊(duì)管理,根據(jù) mysql_history 的操作記錄、前后帶有時(shí)間記錄的業(yè)務(wù)查詢、以及 mysqld-auto.cnf 文件的生成時(shí)間,這些時(shí)間在我們接管之前,接管時(shí)僅檢查了當(dāng)時(shí)的數(shù)據(jù)庫(kù)狀態(tài)、my.cnf 文件中的配置,非常懷疑是這個(gè)操作導(dǎo)致了啟動(dòng)之后 read_only 被開起來,導(dǎo)致業(yè)務(wù)無(wú)法按照預(yù)期寫入,接下來我們對(duì)這個(gè)參數(shù)進(jìn)行測(cè)試。
參數(shù)測(cè)試
在主庫(kù)設(shè)置參數(shù)。
# 配置文件檢查 [root@localhost etc]# cat my.cnf |grep read_only read_only = 0 super_read_only = 0 # 參數(shù)檢查: mysql> select @@read_only,@@super_read_only; +-------------+-------------------+ | @@read_only | @@super_read_only | +-------------+-------------------+ | 0 | 0 | +-------------+-------------------+ 1 row in set (0.00 sec) # 設(shè)置參數(shù) mysql> set PERSIST_ONLY read_only = 1; Query OK, 0 rows affected (0.00 sec)
查看重啟后的參數(shù)變化。
# 重啟數(shù)據(jù)庫(kù) [root@localhost ~]# systemctl restart mysqld_3301 # 查看參數(shù): mysql> select @@read_only,@@super_read_only; +-------------+-------------------+ | @@read_only | @@super_read_only | +-------------+-------------------+ | 1 | 0 | +-------------+-------------------+ 1 row in set (0.00 sec)
通過 strace
來查看數(shù)據(jù)庫(kù)在啟動(dòng)時(shí)讀取了哪些配置文件,以下是相關(guān)配置片段:
15:56:34.828260 stat("/opt/mysql/etc/3301/my.cnf", {st_mode=S_IFREG|0640, st_size=5042, ...}) = 0 <0.000008> 15:56:34.829061 stat("/opt/mysql/data/3301/mysqld-auto.cnf", {st_mode=S_IFREG|0640, st_size=164, ...}) = 0 <0.000006> 15:56:35.154154 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000008> 15:56:35.154228 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000007> 15:56:35.172411 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000007> 15:56:35.172441 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000007> 15:56:35.174142 stat("/opt/mysql/data/3301/mysqld-auto.cnf", {st_mode=S_IFREG|0640, st_size=164, ...}) = 0 <0.000007> 15:56:35.174172 stat("/opt/mysql/data/3301/mysqld-auto.cnf", {st_mode=S_IFREG|0640, st_size=164, ...}) = 0 <0.000007> 15:56:35.357608 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000011> 15:56:35.357643 stat("/opt/mysql/data/3301/auto.cnf", {st_mode=S_IFREG|0640, st_size=56, ...}) = 0 <0.000010> 15:56:35.360019 stat("/opt/mysql/data/3301/mysqld-auto.cnf", {st_mode=S_IFREG|0640, st_size=164, ...}) = 0 <0.000009> 15:56:35.360052 stat("/opt/mysql/data/3301/mysqld-auto.cnf", {st_mode=S_IFREG|0640, st_size=164, ...}) = 0 <0.000008>
測(cè)試結(jié)論
根據(jù)以上排查過程和測(cè)試,數(shù)據(jù)庫(kù)在啟動(dòng)時(shí),讀取完啟動(dòng)時(shí)指定的配置文件,會(huì)去讀 mysqld-auto.cnf
這個(gè)文件,的確是這個(gè)參數(shù)設(shè)置導(dǎo)致 read_only 與標(biāo)準(zhǔn)配置文件預(yù)期不符的。
到此這篇關(guān)于MySQL重啟之后無(wú)法寫入數(shù)據(jù)的問題排查及解決的文章就介紹到這了,更多相關(guān)MySQL重啟后無(wú)法寫入數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MyEclipse連接Mysql數(shù)據(jù)庫(kù)的方法(一)
這篇文章主要介紹了MyEclipse連接Mysql數(shù)據(jù)庫(kù)的方法(一)的相關(guān)資料,非常實(shí)用,具有參考價(jià)值,需要的朋友可以參考下2016-05-05線上MYSQL同步報(bào)錯(cuò)故障處理方法總結(jié)(必看篇)
下面小編就為大家?guī)硪黄€上MYSQL同步報(bào)錯(cuò)故障處理方法總結(jié)(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03mysql主鍵,外鍵,非空,唯一,默認(rèn)約束及創(chuàng)建表的方法
這篇文章主要介紹了mysql主鍵,外鍵,非空,唯一,默認(rèn)約束及創(chuàng)建表的方法,在數(shù)據(jù)庫(kù)中,數(shù)據(jù)表是數(shù)據(jù)庫(kù)中最重要、最基本的操作對(duì)象,是數(shù)據(jù)存儲(chǔ)的基本單位2022-07-07MySQL全局遍歷替換特征字符串的實(shí)現(xiàn)方法
本文主要介紹了MySQL全局遍歷替換特征字符串的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03MySQL數(shù)據(jù)庫(kù)和Redis緩存一致性的更新策略
本文主要介紹了MySQL數(shù)據(jù)庫(kù)和Redis緩存一致性的更新策略問題,文中有詳細(xì)的代碼示例,有需要的朋友可以參考一下2023-04-04