Maria DB Randomly Crashes

Posted September 1, 2020 2.1k views
Linux BasicsMySQLPHPMariaDBLinux Commands

I’ve installed full LAMP stack in my Droplet. I am not an expert but things seem to be working most of the time. But occasionally my SQL server shuts down.

When I try to run “mysql” command through bash window I got the error below. Most people say it is because of missing configuration in SQL ports. But when I restart the droplet everything returns back to normal, at least for a while until another random crash occurs.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

I’ve also checked SQL logs. There is a reoccuring pattern. The below error is logged everytime I have this problem. Can anybody give me some pointers about what it means?

2020-08-10  4:13:38 0 [Note] /usr/sbin/mysqld (initiated by: unknown): Normal shutdown
2020-08-10  4:13:38 0 [Note] Event Scheduler: Purging the queue. 0 events
2020-08-10  4:13:38 0 [Note] InnoDB: FTS optimize thread exiting.
2020-08-10  4:13:38 0 [Note] InnoDB: Starting shutdown...
2020-08-10  4:13:38 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2020-08-10  4:13:38 0 [Note] InnoDB: Buffer pool(s) dump completed at 200810  4:13:38
2020-08-10  4:13:40 0 [Note] InnoDB: Shutdown completed; log sequence number 231485352; transaction id 514172
2020-08-10  4:13:40 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2020-08-10  4:13:40 0 [Note] /usr/sbin/mysqld: Shutdown complete

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.

Submit an Answer
3 answers

Perhaps it’s two different issues. If you can confirm that the mysqld process is alive and accepting connections you may have some bad client-side configuration.

  1. Explicitly pass the right config/flags to to the mysql client in order to connect

e.g. mysql -uuser -p -hlocalhost -P3306

  1. Review the system logs to discover whether the mysqld process is being shutdown due to OOM (out of memory) killer conditions. If the memory consumption of the server is high it might end up sending the shutdown signal to the process. Evidence will be in /var/log/messages or /var/log/syslog



Hi there @mserhatbalik,

In addition to what @andmoo mentioned, I could suggest a couple more things:

  • You could try to optimize the MySQL server, to do so you could follow the steps from this answer here:

  • Another thing that you could do is add some extra memory and possible add a swap file so that in case your server runs out of RAM you would still have some buffer. You can take a look at this tutorial here on how to do that:

  • One more thing that you could try is following the steps from this tutorial on how to optimize your queries and tables:

Hope that this helps!

by Justin Ellingwood
MySQL and MariaDB are popular database management systems that can be used in conjunction with an application or a website. While the querying syntax is easy to learn and very powerful, some operations take a long time. This article will discuss some steps you can take to optimize your queries and table structure.


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:

Hope that this helps!