How to fix MySQL “job failed to start” error
Bobcares.com provides Server Maintenance Services to web hosts, digital marketers and other online businesses.
As part of our services, we manage MySQL servers, and troubleshoot performance issues and server errors.
A common error we’ve seen while trying to start MySQL, usually after an upgrade or a migration is :
# service mysql start
start job failed to start
What is MySQL “job failed to start” error?
MySQL depends on a lot of sub-systems like OS libraries, file system, disk and memory for its proper functioning.
If any of these components develop an issue, MySQL will fail to execute.
Try to start it will result in the “job failed to start” error.
What causes MySQL “job failed to start” error?
Here are a few top reasons we’ve seen:
1. Disk space/inode exhaustion
MySQL uses temporary tables to run queries. So, when MySQL is unable to create new tables, either due to disk space exhaustion or inode exhaustion, the startup script will fail.
In such cases, there might be an entry like this in the log file:
/usr/sbin/mysqld: Disk is full writing '/tmp/yg4KlP8o'
When we see this issue, we first find out if it is a case of the disk space getting full or the inodes getting over. Commands such as
df -h and
df -i comes in handy in such situations.
To resolve it, we find out and delete excess files like spam, old backups, etc. Some common space hogs are:
- Old backups – We’ve seen VPS containers in which old backup archives and uncompressed files taking up almost 50% of disk space. Along with deleting these files, we prevent a recurrence of this issue by setting up disk space alerts, and fixing space issues before it can lead to a service failure.
- Session and Cache files in /tmp – Some apps store session files in /tmp. Usually these files are automatically deleted. But there are times when apps crash mid-execution and these files remain in /tmp, and cause a space overage. We prevent such issues by using an automated /tmp cleaner.
- Spam in mail queue – Some mail servers like Qmail create 4 files for each mail. When such servers are bombarded with thousands of mails, it can easily use up all the inodes in the server, leaving the server unable to create any new file.
- Old apps and database dumps – We’ve seen web users store old copies of web apps and old SQL dumps in their document root. This can also be easily cleared to reclaim space.
- .. and more – There can be a hundred other ways in which space is lost. We fix such issues by systematically analyzing space usage from the server root, and drilling down to the folder that uses the most space.
2. Wrong permissions
All MySQL files should be fully owned by the “mysql” user and all directories it needs access to should have write permission.
For example, MySQL needs write access to the /tmp partition to create temporary folders. If it doesn’t, a service restart will fail with the error:
/usr/sbin/mysqld: Can't create/write to file '/tmp/yg4KlP8o'
To fix this, we make sure the /tmp directory has “777” permissions.
This error can also happen if the mysql data folders & files (/var/lib/mysql in RedHat distros) doesn’t have the right permissions.
Both the user and group should be set to “mysql”.
3. Inadequate memory
VPS servers are usually provisioned with a hard limit on memory.
We’ve seen cases where when the server memory is exhausted, MySQL crashes, and then fails to start.
To fix this, we figure out which process uses memory the most, and tweak the service settings or the apps to cut down its usage.
For example, we’ve found PHP to be the top memory hog in many VPSs. It is usually caused by poorly coded scripts or plugins. We remove or replace these scripts with better ones and setup memory limits for execution that prevents PHP starving other processes.
In sites that have a legitimate increase in traffic, the only solution will be to upgrade the memory.
There are other causes for this error such as startup script errors, log file issues, and more.
If you are unable to resolve these on your own, it is best to seek the assistance of a database expert. Our MySQL admins are online 24/7. Click here to submit a support request.
The error in MySQL “job failed to start” can be caused by disk errors, memory limits, file system issues and more. Here we’ve listed the top 3 reasons for this error and how we fix them.