Question

MYSQL Database Crashes on Server

Good day,

While I was testing an application built with php and laravel that uses a mysql server installed on a digitalocean droplet of 1G ram, 1CPC, etc. The database suddenly crashed and was giving me the error: Job for mysql.service failed because the control process exited with error code. I actually tried to restore the database with another droplet using the same data directory but the error persisted and I discovered that the database might have been corrupted. Please I want to find out why the database suddenly crashed inside a droplet


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.

alexdo
Site Moderator
Site Moderator badge
June 27, 2024

Heya, @orstinoperri

This can happen due to misconfigured MySQL settings can lead to instability. You can use tools like MySQL Tunner to suggest recommended values. This article can help you on how to use the script:

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

Another thing is to examine the MySQL logs to collect information about the error itself. Also the /var/log/messages can give information about the memory problems.

The MySQL error logs can provide detailed information about why the service failed. The logs are typically located at /var/log/mysql/error.log or /var/log/mysqld.log. To view the recent entries:

sudo tail -n 100 /var/log/mysql/error.log

Hope that this helps!

KFSys
Site Moderator
Site Moderator badge
June 20, 2024

Heya @orstinoperri,

This sounds like your Droplet doesn’t have enough RAM to handle the processes thus killing them to avoid crashing itself.

There are usually 3 ways to go about this while I think only 2 out of the 3 ways will help you out in this situation.

First option (long term solution) - Upgrade your Droplet to have more RAM and CPU. That is the most certain way you’ll resolve the issue however, the other 2 options that I’ll present are needed for optimal execusion.

Second Option (short term if used alone) - Add SWAP to your Droplet. You can check this tutorial on how to achieve this - https://www.digitalocean.com/community/tutorial-collections/how-to-add-swap-space

Swap is a portion of hard drive storage that has been set aside for the operating system to temporarily store data that it can no longer hold in RAM. This lets you increase the amount of information that your server can keep in its working memory, with some caveats. The swap space on the hard drive will be used mainly when there is no longer sufficient space in RAM to hold in-use application data.

Third Option (should be considered always but is not enough on it’s own):

Optimize the Database and it’s performance. This is something you need to consider always however it will not be enough to save the DB from crashing it will help for a better performance. This however is a longer answer on what steps to take so I’ll post it separate to not clutter this one.

Bobby Iliev
Site Moderator
Site Moderator badge
June 18, 2024

Hi there,

This sounds like either your server ran out of RAM or disk space.

It is best to check your server log and also MySQL logs at /var/logs. Feel free to share the errors that you get from the logs here so I can advise you further.

There are a few things that you should make sure that you do:

  • You should always have enough disk space, otherwise you are risking your database service from crashing and corrupting your data.
  • On the RAM side of things, you could add some more memory and possibly also consider adding a SWAP file to have some extra buffer, and you could also follow the steps here on how to tweak your MySQL service for better performance:

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

Hope that this helps!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.