Can't create/write to file '/var/tmp/#sql_a41_0.MAI' (Errcode: 2)28

Hi, Please help me to solve this type error on centos 7
"Can't create/write to file '/var/tmp/#sql_a41_0.MAI' (Errcode: 2)28"

6 Replies

It's likely that the disk that MySQL is storing data on is completely full. I'd recommend running the following commands to check to see if it has free space or free inodes:

df -h
df -ih

If everything checks out then there might be a problem with the permissions for the directory or file that MySQL is trying to write to. You can check permissions for a file or directory, /etc/example for example, with:

ls -al /etc/example

From there, if things look off, you can change the permissions for a file or directory with chmod.

Hi, thank you for your reply

after df -h, result is

[root@linode ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 24G 4.6G 84% /
devtmpfs 987M 0 987M 0% /dev
tmpfs 990M 0 990M 0% /dev/shm
tmpfs 990M 107M 884M 11% /run
tmpfs 990M 0 990M 0% /sys/fs/cgroup
tmpfs 198M 0 198M 0% /run/user/0

and after df -ih, result is

[root@linode ~]# df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/root 1.9M 122K 1.7M 7% /
devtmpfs 247K 394 247K 1% /dev
tmpfs 248K 1 248K 1% /dev/shm
tmpfs 248K 531 247K 1% /run
tmpfs 248K 17 248K 1% /sys/fs/cgroup
tmpfs 248K 1 248K 1% /run/user/0

and after

[root@linode ~]# ls -al /var/tmp
total 8
drwxrwxrwt. 2 mysql mysql 4096 May 29 11:38 .
drwxr-xr-x. 20 root root 4096 Apr 10 12:39 ..

actually i am new to this, is this correct?

Also when i am trying to mysqldump showing following error -

[root@linode ~ html]# mysqldump -u root -p databasename> filename.sql
Enter password:
mysqldump: Error: 'Can't create/write to file '/var/tmp/#sql_a41_2.MAI' (Errcode : 2)' when trying to dump tablespaces
mysqldump: Couldn't execute 'show fields from activated': Can't create/write t o file '/var/tmp/#sql_a41_0.MAI' (Errcode: 2) (1)

It looks like your Linode's disk has plenty of space, and the permissions look fine as well though I think in most setups /var/tmp is owned by the root user. You can change it to being owned by the root user with chown if you'd like:

chown root:root /var/tmp

From my own testing MySQL worked just fine with a /var/tmp directory owned by it, so I don't think it's necessary, just something that I noticed.

Aside from that, there's a few different things that could be causing this. There's a good thread on Stack Overflow that has some suggestions. For example, you could try changing the default temporary file directory by adding the following lines to your /etc/my.cnf file:

[mysqld]
tmpdir=/tmp

Then, restart MySQL:

systemctl restart mysqld

@mjones, I followed all the above suggested step
but when i am trying to connect mysql using 'mysql -u root -p' following error showing.

[root@linode ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Thank you @mjones, working everything fine.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct