解決Mysql?Binlog文件太大導(dǎo)致無(wú)法解析問(wèn)題
正文
由于業(yè)務(wù)寫入了一條大事務(wù),導(dǎo)致 MySQL 的 binlog 膨脹。在解析大的 binlog 時(shí),經(jīng)常會(huì)遇到這個(gè)問(wèn)題,導(dǎo)致無(wú)法解析,沒有其他工具的情況下,很難分析問(wèn)題。
故障現(xiàn)象
由于業(yè)務(wù)寫入了一條大事務(wù),導(dǎo)致 MySQL 的 binlog 膨脹。在解析大的 binlog 時(shí),經(jīng)常會(huì)遇到這個(gè)問(wèn)題,導(dǎo)致無(wú)法解析,沒有其他工具的情況下,很難分析問(wèn)題。
故障復(fù)現(xiàn)
[root@xuzong mysql]# ls -lh mysql-bin.003300 -rw-r----- 1 my3696 mysql 6.7G Oct 30 16:24 mysql-bin.003300 [root@xuzong mysql]# /usr/local/mysql-5.7.35/bin/mysqlbinlog -vv mysql-bin.003300 > 1.sql mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.334z3P' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device) mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
猜測(cè)
- 可能是配置文件中 tmpdir 的問(wèn)題,但是修改這個(gè)得重啟 MySQL。
- 能不能在不重啟 MySQL 的情況下,修改這個(gè)臨時(shí)空間。
驗(yàn)證猜測(cè)
猜測(cè)一
看一下 my.cnf 設(shè)置的 tmpdir,發(fā)現(xiàn)并不是使用的這個(gè)參數(shù),看來(lái)猜測(cè)一不對(duì)。
[root@mysql mysql]# cat my.cnf | grep tmpdir tmpdir = /data1/dbatemp
猜測(cè)二
網(wǎng)上搜了一下,大部分是講臨時(shí)表滿怎么解決的,也就是猜測(cè)一的方案,并沒有很明確的方法來(lái)修改 mybinlog 解析時(shí),所使用的的臨時(shí)句柄占用空間。
問(wèn)題分析
只能看看源碼,看一下 mysqlbinlog 到底是怎么獲取 tmpdir 的。
mysqbinlog.cc
int main(int argc, char** argv)
{
........
MY_TMPDIR tmpdir;
tmpdir.list= 0;
if (!dirname_for_local_load)
{
if (init_tmpdir(&tmpdir, 0))
exit(1);
dirname_for_local_load= my_strdup(PSI_NOT_INSTRUMENTED,
my_tmpdir(&tmpdir), MY_WME);
}
........
}
mf_tempdir.cc
my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
{
char *end, *copy;
char buff[FN_REFLEN];
DBUG_ENTER("init_tmpdir");
DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL"));
Prealloced_array<char*, 10, true> full_list(key_memory_MY_TMPDIR_full_list);
memset(tmpdir, 0, sizeof(*tmpdir));
if (!pathlist || !pathlist[0])
{
/* Get default temporary directory */
pathlist=getenv("TMPDIR"); /* Use this if possible */ //這里能看到是獲取的機(jī)器環(huán)境變量
#if defined(_WIN32)
if (!pathlist)
pathlist=getenv("TEMP"); //windows是temp
if (!pathlist)
pathlist=getenv("TMP"); //linux是tmp
#endif
if (!pathlist || !pathlist[0])
pathlist= DEFAULT_TMPDIR;
}
........
}好家伙,竟然是獲取的機(jī)器環(huán)境變量,那么這個(gè)問(wèn)題就解決了。
問(wèn)題處理
臨時(shí)修改一下機(jī)器的 tmpdir 變量即可。
[root@mysql mysql]# export TMPDIR="/data1"
[root@mysql mysql]# echo ${TMPDIR:-/tmp}
[root@xuzong mysql]# /usr/local/mysql-5.7.35/bin/mysqlbinlog -vv mysql-bin.003300 > 1.sql總結(jié)
- 有問(wèn)題還是要看看源碼。
- 可以考慮使用 binlog 解析工具,比如 bin2sql 解決問(wèn)題。
- 可以看看慢日志里是否有記錄。
補(bǔ)充
原來(lái)這個(gè)問(wèn)題在 MySQL 官方手冊(cè) 中有所描述,在此做一個(gè)補(bǔ)充。

When running mysqlbinlog against a large binary log, be careful that the filesystem has enough space for the resulting files. To configure the directory that mysqlbinlog uses for temporary files, use the TMPDIR environment variable.
以上就是解決Mysql Binlog文件太大導(dǎo)致無(wú)法解析問(wèn)題的詳細(xì)內(nèi)容,更多關(guān)于Mysql Binlog大文件解析的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- MySQL?Binlog日志的記錄模式寫入機(jī)制文件操作詳解
- MySQL binlog日志記錄格式寫入機(jī)制及相關(guān)參數(shù)講解
- 真的了解MySQL中的binlog和redolog區(qū)別
- Mysql 數(shù)據(jù)庫(kù)開啟binlog的實(shí)現(xiàn)步驟
- MySQL?binlog格式之Row和Statement語(yǔ)句詳解
- Mysql-binlog的查看實(shí)踐
- 清理MySQL Binlog二進(jìn)制日志的三種方式
- MySQL binlog日志清理的方案分享
- mysql binlog日志查詢不出語(yǔ)句問(wèn)題及解決
- MySQL安全刪除binlog日志的詳細(xì)步驟
- MySQL中Binlog日志的使用方法詳細(xì)介紹
- Mysql binlog的查看方法
相關(guān)文章
Mysql數(shù)據(jù)庫(kù)之常用sql語(yǔ)句進(jìn)階與總結(jié)
這篇文章主要介紹了Mysql數(shù)據(jù)庫(kù)之常用sql語(yǔ)句,總結(jié)分析了MySQL數(shù)據(jù)庫(kù)常用的查詢、條件查詢、排序、連接查詢、子查詢等相關(guān)操作技巧,需要的朋友可以參考下2019-11-11
MySQL中關(guān)于超鍵和主鍵及候選鍵的區(qū)別
這篇文章主要介紹了MySQL中關(guān)于超鍵和主鍵及候選鍵的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Ubuntu 18.04下mysql 8.0 安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了Ubuntu 18.04下mysql 8.0 安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05

