解決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
總結
- 有問題還是要看看源碼。
- 可以考慮使用 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數(shù)據(jù)庫之常用sql語句進階與總結
這篇文章主要介紹了Mysql數(shù)據(jù)庫之常用sql語句,總結分析了MySQL數(shù)據(jù)庫常用的查詢、條件查詢、排序、連接查詢、子查詢等相關操作技巧,需要的朋友可以參考下2019-11-11Ubuntu 18.04下mysql 8.0 安裝配置方法圖文教程
這篇文章主要為大家詳細介紹了Ubuntu 18.04下mysql 8.0 安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05