1

At the moment, MySQL Server is using /tmp as it's temporary directory, and I'd like to change that, because it's running into storage issues.

Following this post: How to change the MySQL tmp location on CentOS as I'm on Scientific Linux and generally CentOS works pretty well as an analog, I've done the following, all under sudo:

mkdir /home/mysqltmp

chmod 1777 /home/mysqltmp

nano /etc/my.cnf

Add below line under the [mysqld] section and save the file
tmpdir=/home/mysqltmp

systemctl restart mysqld

This restart fails. If I restore the old my.cnf without the change, it works perfectly, which suggests to me that there's a problem either with the configuration file itself, or with how I've setup permissions, and given my (limited) Linux experience, I'm pretty sure that it's a permissions problem.

UPDATE: Looking at mysqld.log, it appears this is indeed a permissions issue:

2018-05-16T00:01:05.211853Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.22) starting as process 5929 ...
2018-05-16T00:01:05.214159Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-05-16T00:01:05.214186Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-16T00:01:05.214191Z 0 [Note] InnoDB: Uses event mutexes
2018-05-16T00:01:05.214194Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-05-16T00:01:05.214197Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-05-16T00:01:05.214202Z 0 [Note] InnoDB: Using Linux native AIO
2018-05-16T00:01:05.214382Z 0 [Note] InnoDB: Number of pools: 1
2018-05-16T00:01:05.214459Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysqld: Can't create/write to file '/home/mysqltmp/ibAcknwl' (Errcode: 13 - Permission denied)
2018-05-16T00:01:05.214535Z 0 [ERROR] InnoDB: Unable to create temporary file; errno: 13
2018-05-16T00:01:05.214542Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2018-05-16T00:01:05.214548Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2018-05-16T00:01:05.214551Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2018-05-16T00:01:05.214554Z 0 [ERROR] Failed to initialize builtin plugins.
2018-05-16T00:01:05.214557Z 0 [ERROR] Aborting

Does anyone see what I'm doing wrong?

Update 2: This does appear to be an selinux thing. chown does not fix the problem, and in the audit logs there's a number of AVC denied {write} messages for that directory.

selinux is entirely opque to me - is there a fix for this?

  • does sudo chown mysql.mysql /home/mysqltmp help? Though I am more inclined for it to be a SELinux thing.... – Rui F Ribeiro May 16 '18 at 8:00
  • See update. It's an SELinux thing. – Fomite May 17 '18 at 0:36
0

I came across this very same issue today. It gave me enough hints to have the idea of googling for "selinux mysql write permission". Which immediately gave me the answer, which you can read on this Oracle blog post. In case Oracle would take down the link as they are quite used to, you can also get it from the wayback machine, but be patient and scroll down to get the text.

I will just give here a few hints:

  1. Check your selinux status with (root shell) command getenforce
  2. If it replies with 'ENFORCING', try setting it to 'PERMISSIVE' with command setenforce 0
  3. Then try to restart mysqld and check that it is now working
  4. reset selinux back to normal with command setenforce 1

Once you have demonstrated that selinux is the culprit for mysqld not working, you can't just disable it, because that is not secure. You have to find out how to add an exception specific to mysqld in its configuration.

For that part I will let you figure out by yourself using the link I gave and SELinux documentation as I am not a specialist and thus would not try to give advice about something I don't fully understand

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.