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.

×
2 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

BR

Andrew

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:

https://www.digitalocean.com/community/questions/how-to-tweak-mysql-mariadb-configuration-for-increased-performance-and-stability

  • 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:

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04

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

https://www.digitalocean.com/community/tutorials/how-to-optimize-queries-and-tables-in-mysql-and-mariadb-on-a-vps

Hope that this helps!
Regards,
Bobby

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.
Submit an Answer