Knowledge Base
MilesWeb / DigitalOcean

MySQL on Ubuntu Droplet Keeps Crashing – Reasons and Solutions

Approx. read time : 4 min

Do you get the error “Error establishing a database connection” message often?

If you do then there the possible reason could be MySQL service crash on your DigitalOcean Droplet.

Basically, the reasons for MySQL crash are different and may be due to lack of resources on the server to bad website scripts.

Let’s check the common reasons that cause MySQL crashing and tips to fix them.

Reasons for MySQL crashing in DigitalOcean Droplet

A MySQL server crash is really critical because all your websites will be affected by this. Therefore, it needs a quick solution.

To resolve this issue, it is important to find out the reason for MySQL failure.

Check below the different reasons lead to the crashing of MySQL service on the Droplet.

1. Buggy scripts

As per our experts that manage DO Droplets, there are often buggy php scripts seen overloading the server. These scripts comprise of bad mysql queries that might consume server resources. In addition, they simply keep on running on the server without any result.

Same is the case with WordPress websites, often certain plugins lead to MySQL failure. This further gives rise to database errors on the website.

2. Lack of server resources

The next reason for MySQL crash could be lack of server resources.

When Digital Ocean provides minimal configuration droplets that are stuffed with too many websites, it might lead to MySQL crash. These droplets comprise of a total 512 MB memory. This low memory won’t be able to handle high traffic websites, manage server processes, etc. This results in ‘Out of Memory’ issues in droplet.

In case, the physical memory (RAM) is full, PHP scripts use a buffer memory called “Swap” to process the request.

After we plan to use this buffer space, we need to assign this Swapspace when the initial set up of Droplet is done.
If there isn’t an additional space created in the Droplet, there can be lack of memory leading to MySQL crash.

3. Malicious attacks

It rarely happens that there high resource usage by MySQL is because of valid website access. Attacks involving xmlrpc.php file of WordPress can also be one of the reasons behind the MySQL crash. In this attack, hacker takes the efforts to break into the admin panel of WordPress by using too many hits to the website.

Due to this, the server fails to handle the large number of requests and can crash.

4. Broken databases

Broken databases can also lead to database errors in the website. The reason behind this to happen is the database files corruption. Mostly, disk full issues, permission problems, etc. can also lead to MySQL crash.

Ideas to Fix MySQL Crashing in DigitalOcean Droplets

The solution to fix the crash varies for different reasons. Let’s see these fixes in detail.

1. Assign Adequate Server Resources

In this solution, you are allocated with adequate amount of resources on the droplet. This mainly depends on the server’s functionality. The Droplet should comprise of enough processing power, memory, disk space, swap space, etc. on the server.

The DigitalOcean droplets don’t have swap space created by default. Here, our technical support team will check for the resources on the server and preserve adequate percentage of memory for swap. For example, if a droplet comes with 4GB memory, based on the type of websites, a swap space of 1GB would be perfect.

But, if constant use of swap space on the server is detected, it is recommended to permanently upgrade the memory of Droplet.

2. Service Optimization

Even though the server has enough resources, if the MySQL configuration is wrong, it can lead to crash. Therefore, if there is a frequent MySQL crash on a droplet, slow queries are enabled in MySQL by our experts. You will find those logged to the mysql log file available at /var/log/mysql/log-slow-queries.log. Due to this, it becomes easy to identify the specific sites that cause the problem.

If there is a problem with the website script, our team helps to fix it. This is also applicable to the trouble cause by the plugins on WordPress websites.

Moreover, the MySQL service variables like max_connections, query_cache_limit, table_cache, etc. are also optimized by our team.

To get the best results, this optimization is extended to the web server too. It includes changes such as restricting values such as Max_clients, StartServers in Apache configuration, selecting the correct processing module, etc.

3. Prevent Malicious Attacks

When an attack is observed on a droplet, proper firewall is implemented to protect these malicious attacks. For instance, in xmlrpc attack, we disable xmlrpc method on the server as a whole, install plugins to stop attack, etc.
Also, our experts recommend the customers to proactively set proper defending mechanisms in the droplets.

4. Check the Database Periodically

Always do a periodic check of the databases running on the server. With this you can track and repair corrupt tables, if any. Also, we do a scheduled database check using the cron jobs. This comprises of checking the server disk space usage, MySQL log file size, etc. as well. This will help to omit the MySQL crash due to disk full issues.

Conclusion

Lastly, it can be said that MySQL crashing in DigitalOcean droplets happens mainly due to bad MySQL configuration, scarcity of resources, buggy scripts, etc. If still you face any issue while resolving the MySQL crash, you can always contact our support team.

Also Read: MySQL Database (cPanel)

Also Read: How to Install htop to Check the Droplet’s Memory Usage?

Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna