Is MySQL Database Corrupt?

  • Posted January 25, 2016
  • NoSQL

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?



The outputs for the ‘ps’ command are here

I’ve ran a service mysql status and it returned mysql stop/waiting. I’ve ran service mysql start and got Job failed to start. Tried stopping the service and I got Unknown instance.

@administrator72 - You’re defaults also allows for TCP port 3306, so socket /var/run/mysql/mysql.sock is optional. If you want to try using TCP port 3306, you can give mysqladmin the arguments –port=3306 --protocol=TCP along with the other arguments I gave in my previous comment.

I did not see your output to the ‘ps’ command, so maybe mysql just gave up after detecting the page corruption. You can verify this with service mysql status. If mysql can’t start at all after using service mysql start, then your choices are limited. I recommend taking a snapshot of your datadir /var/lib/mysql to somewhere else for a later post-mortem, then try recovering from backup if you have a lot of data you want to recover. Good luck.

I’ve ran couple of the diagnostics as mentioned above with the following outputs

my_print_defaults mysqld -

mysqladmin status -

As you can see on the mysqladmin status output it says it can’t connect to the MYSQL through the socket. I’ve tried /var/run/mysqld/mysqld.sock to se if it is there but No such file or directory is returned.

Need more info to diagnose a db page corruption. Try running the following diagnostic commands to see the state of your mysql installation (note: you’ll need to enter your mysql root password when prompted, or use a different mysql administrator account/pw).

my_print_defaults mysqld       ## This might be --mysqld on your system
mysqladmin --version
mysqladmin status --user root --password
mysqlshow  --user root --password
ps -elf | grep mysql

Mask out any sensitive info if you post the output.

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

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.

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