溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MySQL 中怎么創(chuàng)建臨時目錄

發(fā)布時間:2021-08-13 16:52:32 來源:億速云 閱讀:130 作者:Leah 欄目:數(shù)據(jù)庫

MySQL 中怎么創(chuàng)建臨時目錄,針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

MySQL 服務(wù)器設(shè)置的 binlog 單文件最大為 1GB,偶然發(fā)現(xiàn)會有十幾 GB 大小的 binlog 文件,從產(chǎn)生的時間上看像是某個 cron job 使用了超大

在使用 mysqlbinlog 將 binary log 轉(zhuǎn)換為文本文件時,發(fā)現(xiàn)根分區(qū)很快就被塞滿了,使用 lsof 發(fā)現(xiàn) mysqlbinlog 在往 /tmp 下寫臨時文件:

# lsof -p 17423
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqlbinl 17423 root 1w REG 0,19 791765366 3186036 /mfs/user/xupeng/tmp/bigbinlogs/bigbinlog.sql
mysqlbinl 17423 root 2u CHR 136,7 0t0 10 /dev/pts/7
mysqlbinl 17423 root 3r REG 0,19 13863171331 3172073 /mfs/user/xupeng/tmp/bigbinlogs/log.000323
mysqlbinl 17423 root 4u REG 8,1 612122624 135332782 /tmp/tmp.rWTNda (deleted)
mysqlbinl 17423 root 5u REG 8,1 2490368 135332784 /tmp/tmp.spKjTA (deleted)

看 mysqlbinlog 的 Man page,發(fā)現(xiàn)并沒有參數(shù)可以指定臨時目錄,翻了一下 mysqlbinlog (client/mysqlbinlog.cc) 的代碼,看到了下面的代碼:

MY_TMPDIR tmpdir;
tmpdir.list= 0;
if (!dirname_for_local_load)
{
if (init_tmpdir(&tmpdir, 0))
exit(1);
dirname_for_local_load= my_strdup(my_tmpdir(&tmpdir), MY_WME);
}

init_tmpdir 定義在 mysys/mf_tempdir.c 中:

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”));

pthread_mutex_init(&tmpdir->mutex, MY_MUTEX_INIT_FAST);
if (my_init_dynamic_array(&tmpdir->full_list, sizeof(char*), 1, 5))
goto err;
if (!pathlist || !pathlist[0])
{
/* Get default temporary directory */
pathlist=getenv(“TMPDIR”); /* Use this if possible */
#if defined( __WIN__) || defined(__NETWARE__)
if (!pathlist)
pathlist=getenv(“TEMP”);
if (!pathlist)
pathlist=getenv(“TMP”);
#endif
if (!pathlist || !pathlist[0])
pathlist=(char*) P_tmpdir;
}

所以在運行 mysqlbinlog 之前設(shè)置 TMPDIR 這個環(huán)境變量就好了。

MySQL server 和 客戶端工具都使用這個臨時目錄查找策略,怪不得使用 mysqlbinlog tmp directory 作為關(guān)鍵詞沒有搜到需要的結(jié)果,而使用 mysql tmp directory 作為關(guān)鍵詞,第一條搜索結(jié)果就是 ,選擇正確的關(guān)鍵詞很重要啊。

關(guān)于MySQL 中怎么創(chuàng)建臨時目錄問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI