Is MySQL Database Corrupt?

Hi, I’ve had the “Error establishing a database connection” for several days now. I’ve tried restarting the droplet but to no avail. I’ve ran a mysql error log and got this back (please copy and paste link).

Can anyone suggest a solution/help please?


Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello, all

I will recommend you to check our article on How To Debug the WordPress Error Establishing Database Connection:

This crash is most likely due to your system running out of memory. I’d suggest that you add a swap file to give yourself a bit more of a buffer. Check out this tutorial:

How To Add Swap on Ubuntu

You will most definitely need to upgrade your droplet as you’re running out of memory and your application/website needs more resources in order to continue to operate.

What you can also do is to use the MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

  • SSH to your Droplet
  • Download the script:
wget -O
  • Then execute it:

The script would run multiple checks against your MySQL instance, all checks done by MySQLTuner are documented here.

Also as stated in the official documentation, it is still extremely important for you to fully understand each change you make to a MySQL database server. If you don’t understand portions of the script’s output, or if you don’t understand the recommendations, you should consult a knowledgeable DBA or system administrator that you trust.

As a good practice make sure to always test your changes on staging environments before implementing them on your production database.

On the same note, if you want to have a worry-free MySQL hosting and focus on your application, I would recommend trying out the DigitalOcean Managed Databases:

This was mini tutorial was posted from bobbyiliev in this question in our community:

You can also create a simple bash script to check if MySQL is running and if not to restart it.


# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/ > /dev/null 2>&1

Hope that this helps! Regards, Alex

MySQL can be a tricky service to troubleshoot and can often cause quite a number of headaches. Being we only provide self-managed hosting, we are limited in what we can do for you in such a situation. We may not be able to login and troubleshoot this for you, however we can provide a few different ideas to help guide you in resolving this situation.

The most common cause of MySQL stopping or failing to start is a resullt of memory (ie RAM) issues. This is largely because MySQL is a very resource intensive service. Nearly everything it does uses a good chunk of RAM and IO. The best way to be sure is to try and start MySQL using the command:

For Ubuntu/Debian sudo service mysql start For CentOS/Fedora sudo systemctl start mariadb.service

After doing such an event, it will normally let you know if it fails. If it does, I recommend reviewing the MySQL log file to see what issue occurred. The log file location is normally at:

For Ubuntu/Debian /var/log/mysql/error.log For CentOS/Fedora /var/log/mariadb/mariadb.log

It should tell you what error occurred if a MySQL error occurred. If you see errors such as “mmap can’t allocate,” then you know you are hitting memory issues. Potential fixes for that are tuning your MySQL settings (using a binary such a mysqltuner, which is available via the package manager), optimizing any using MySQL (such as a website), and resizing the droplet to a larger size to allow for more memory usage. I strongly recommend doing the first two first, and save doing the resize for when you are sure nothing else can be optimized to use less memory.

Another potential problem could be a lack of disc space or inodes on your droplet. The MySQL log will normally indicate this, but you could confirm it using commands such as:

sudo df -h sudo df -i

If you see you are very near 100% usage, you will want to either reduce the disc space/inode usage, or resize to a larger package to allow more disc space/inodes. If you are seeing high disc space usage, you can locate large files using a command such as:

sudo find / -type f -size +1G -exec du -h {} ; 2>/dev/null

Another problem could be an application using too much of the MySQL service. You can normally verify this by checking your application’s setup, the queries it uses, and any related logs for the application. If you see high traffic that is abnormal (like a ton of xmlrpc.php requests for example), you would want to investigate that to rectify that situation. Often, fixing something like that will resolve the MySQL issue.

Hope it helps, Jason Colyer DigitalOcean Platform Support Lead