解決Mysql?Binlog文件太大導致無法解析問題
正文
由于業(yè)務寫入了一條大事務,導致 MySQL 的 binlog 膨脹。在解析大的 binlog 時,經(jīng)常會遇到這個問題,導致無法解析,沒有其他工具的情況下,很難分析問題。
故障現(xiàn)象
由于業(yè)務寫入了一條大事務,導致 MySQL 的 binlog 膨脹。在解析大的 binlog 時,經(jīng)常會遇到這個問題,導致無法解析,沒有其他工具的情況下,很難分析問題。
故障復現(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)
猜測
- 可能是配置文件中 tmpdir 的問題,但是修改這個得重啟 MySQL。
- 能不能在不重啟 MySQL 的情況下,修改這個臨時空間。
驗證猜測
猜測一
看一下 my.cnf 設置的 tmpdir,發(fā)現(xiàn)并不是使用的這個參數(shù),看來猜測一不對。
[root@mysql mysql]# cat my.cnf | grep tmpdir tmpdir = /data1/dbatemp
猜測二
網(wǎng)上搜了一下,大部分是講臨時表滿怎么解決的,也就是猜測一的方案,并沒有很明確的方法來修改 mybinlog 解析時,所使用的的臨時句柄占用空間。
問題分析
只能看看源碼,看一下 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 */ //這里能看到是獲取的機器環(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;
}
........
}好家伙,竟然是獲取的機器環(huán)境變量,那么這個問題就解決了。
問題處理
臨時修改一下機器的 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é)
- 有問題還是要看看源碼。
- 可以考慮使用 binlog 解析工具,比如 bin2sql 解決問題。
- 可以看看慢日志里是否有記錄。
補充
原來這個問題在 MySQL 官方手冊 中有所描述,在此做一個補充。

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文件太大導致無法解析問題的詳細內(nèi)容,更多關于Mysql Binlog大文件解析的資料請關注腳本之家其它相關文章!
- MySQL?Binlog日志的記錄模式寫入機制文件操作詳解
- MySQL binlog日志記錄格式寫入機制及相關參數(shù)講解
- 真的了解MySQL中的binlog和redolog區(qū)別
- Mysql 數(shù)據(jù)庫開啟binlog的實現(xiàn)步驟
- MySQL?binlog格式之Row和Statement語句詳解
- Mysql-binlog的查看實踐
- 清理MySQL Binlog二進制日志的三種方式
- MySQL binlog日志清理的方案分享
- mysql binlog日志查詢不出語句問題及解決
- MySQL安全刪除binlog日志的詳細步驟
- MySQL中Binlog日志的使用方法詳細介紹
- Mysql binlog的查看方法
相關文章
Mysql中replace與replace into的用法講解
今天小編就為大家分享一篇關于Mysql中replace與replace into的用法講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03
使用mysqldump對MySQL的數(shù)據(jù)進行備份的操作教程
這篇文章主要介紹了使用mysqldump對MySQL的數(shù)據(jù)進行備份的操作教程,示例環(huán)境基于CentOS操作系統(tǒng),需要的朋友可以參考下2015-12-12
使用Kubernetes集群環(huán)境部署MySQL數(shù)據(jù)庫的實戰(zhàn)記錄
這篇文章主要介紹了使用Kubernetes集群環(huán)境部署MySQL數(shù)據(jù)庫,主要包括編寫 mysql.yaml文件,執(zhí)行如下命令創(chuàng)建,通過相關命令查看創(chuàng)建結(jié)果,對Kubernetes部署MySQL數(shù)據(jù)庫的過程感興趣的朋友一起看看吧2022-05-05
MySQL數(shù)據(jù)庫中正則表達式(Regex)和like的區(qū)別詳析
MySQL正則表達式是一種強大的文本匹配工具,允許執(zhí)行復雜的字符串搜索和處理,這篇文章主要介紹了MySQL數(shù)據(jù)庫中正則表達式(Regex)和like區(qū)別的相關資料,文中通過代碼需要的朋友可以參考下2025-11-11
MySQL數(shù)據(jù)庫中UUID主鍵性能優(yōu)化的方案詳解
最近我們在性能優(yōu)化中發(fā)現(xiàn)了一個隱蔽的問題,數(shù)據(jù)庫的寫入和查詢性能在數(shù)據(jù)量增長后出現(xiàn)明顯下降,原因竟然是UUID,本文將剖析UUID在數(shù)據(jù)庫中的真實影響并提供更優(yōu)化的解決方案,希望對大家有所幫助2026-02-02
mysql指定某行或者某列的排序?qū)崿F(xiàn)方法
這篇文章主要介紹了mysql指定某行或者某列的排序,需要的朋友可以參考下2017-05-05

