Can’t create/write to file ‘/tmp/’ (Errcode: 13) MySQL error


Today one specific VPS server had a MySQL failure. It is a critical MySQL server, so… the first thing I tried was to restore the service while starting the MySQL daemon, but it never did:

 Timeout error occurred trying to start MySQL Daemon. Starting MySQL: [FAILED]

And the only thing I got at the logs was this:

/usr/libexec/mysqld: Can't create/write to file '/tmp/95fb1' (Errcode: 13) InnoDB: Error: unable to create temporary file; errno: 13 [ERROR] Can't init databases [ERROR] Aborting /usr/libexec/mysqld: Shutdown complete

The error speaks for itself: “Error: unable to create temporary file“. On most unix / linux systems the temporary files are created at /tmp directory, and that already gives us a clue about what’s going on. But we need more information, that’s when the perror commands comes in:

The error number is 13, as seen on the logs:

Can’t create/write to file ‘/tmp/’ (Errcode: 13)

So, let’s see what an error 13 really means:

perror 13

And we see it’s a permission denied error:

[my@server ~]$  perror 13 OS error code 13: Permission denied

The solution?

Set the correct owner and permissions to /tmp by running this commands:

chown root.root /tmp -v chmod 1777 /tmp -v

Now restart MySQL to test it:

/etc/init.d/mysqld start

That’s all, now your MySQL server should be able to start without any warnings or failures:

 [my@server:~]service mysqld start Starting mysqld:                                           [  OK  ]

Leave a Reply