ScaleScaleScaleScale

Tips / Nginx


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

mysql

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  ]

Popular search terms:

  • mysqld: Can\t create/write to file \ (Errcode: 13 Permission denied)
  • ^G/usr/libexec/mysqld: File \\ not found (Errcode: 13
  • Can\t read dir of \/etc/mysql/mysql conf d/\ (Errcode: 13 - Permission denied)
  • Errcode: 13 - Permission denied
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Pmizzle.

    Hi, I’m new to this so please forgive my ignorance if I don’t use the correct terms. Haveing this problem with XAMPP 5.6.19 on my MacBook OSX Yosemite 10.10.5

    I’m using the terminal to run the command lines. Your first one: “chown root.root /tmp -v” gives me this error: “chown: root.root: illegal user name”

    I’m using my best guest to replace one of these “root” with my username. I tried on both username.root and root.username

    Still get the error. What am I doing wrong?

    • Esteban Borges

      The message is clear: “chown: root.root: illegal user name”, maybe ‘root’ user is not available on your OS.

  • The message is clear: “chown: root.root: illegal user name”, maybe ‘root’ user is not available on your OS.