Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a temporary directory in MySQL

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to create a temporary directory in MySQL? for this question, this article introduces in detail the corresponding analysis and solutions, hoping to help more partners who want to solve this problem to find a more simple and easy way.

The binlog single file set by the MySQL server is the largest 1GB, and accidentally found that there will be a binlog file with a size of more than ten GB. From the time it is generated, it seems that a certain cron job has used a very large file.

When you use mysqlbinlog to convert binary log to a text file, you find that the root partition is quickly full, and you use lsof to find that mysqlbinlog is writing a temporary file to / 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 8pm 1 612122624 135332782 / tmp/tmp.rWTNda (deleted)

Mysqlbinl 17423 root 5u REG 8 2490368 135332784 / tmp/tmp.spKjTA (deleted)

Look at mysqlbinlog's Man page and find that there is no parameter to specify a temporary directory. After looking through the code of mysqlbinlog (client/mysqlbinlog.cc), you can see the following code:

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 is defined in 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 (& 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

}

So it's fine to set the environment variable TMPDIR before running mysqlbinlog.

Both MySQL server and client tools use this temporary directory search strategy, so it's no wonder that using mysqlbinlog tmp directory as the keyword did not find the desired results, while using mysql tmp directory as the keyword, the first search result is that it is important to choose the right keyword.

This is the answer to the question about how to create a temporary directory in MySQL. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report