Question

Error Establishing a database connection issues

I’m relatively new to using digital ocean and VPS hosting in general. I recently used the “how to debug Wordpress” tutorial and based on the results, I’m running out of memory.

I don’t see how that’s possible. It’s a single page website with no traffic. The server has 1g of memory and 30gb of disk space. Furthermore, I have multiple websites running on the 5$ version of DigitalOcean that don’t run into this issue even though they have many pages and receive some traffic.

Is there any way for me to see what’s eating up all my memory?

Also, I followed the instruction on how to turn off XML-RPC so that won’t be the cause.

Subscribe
Share

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

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 http://mysqltuner.pl/ -O mysqltuner.pl
  • Then execute it:
perl mysqltuner.pl

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:

https://www.digitalocean.com/products/managed-databases-mysql/

This was mini tutorial was posted from bobbyiliev in this question in our community: https://www.digitalocean.com/community/questions/how-to-tweak-mysql-mariadb-configuration-for-increased-performance-and-stability

You can also create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# 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
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps! Regards, Alex

Hey, everyone, I’m back. So basically I’m still ocasionally running into the same problem. I have five different digital ocean servers. Three of them run perfectly fine on $5 servers with more traffic and web pages. There’s absolutely no reason this $10 server should be running out of memory.

I’ve been routinely monitoring htop and at no point does my memory reach the upper limits. However, for some reason, my error log is showing my server as running out of memory.

I even went so far as to make a snapshot of my data and create a new droplet, put that snapshot on a new server. This hasn’t made things any better.

It has to be one of my plugins or somehow my database is messed up. I’m considering making a new droplet and recreating my website from the ground up. It’s only a few pages so it won’t take too long. However, I don’t want to have to resort to this.

@semipro Install htop on the other server as well. It doesn’t cost any RAM or CPU, when it’s not running. Then look at the differences in like Apache, MySQL, etc.

Are you running the same version of Ubuntu, Apache, PHP and MySQL on both servers?

When MySQL crashes, then before starting it again, run tail -50 /var/log/mysql/error.log

I’ve been monitoring htop for 15 minutes now and haven’t noticed any more spikes. If I go to my homepage the CPU quickly jumps to 20% - 40% before going back to 1%. The memory goes up to just under 600M.

Currently everything is running fine with no database errors but I’m certain it will occur again.

What’s using the most memory is /usr/sbin/mysqld at about a constant 17.5%.

/usr/sbin/apache2 -k start at 10%

and then /usr/lib/snapd/snapd and /usr/bin/python3 /usr/bin/fail2ban-server -s /var/run/fail2ban/fail2ban.sock -p /var/run/fail2ban/fail2ban.pid -x -b are both using 1-2%

And finally the last few lines of the command are below. Sorry I would not allow me to place it all in one post.

2017-06-16T23:52:16.138611Z 0 [Note] Executing 'SELECT * FROM 2017-06-16T23:52:16.138616Z 0 [Note] Beginning of list of non-natively partitioned tables 2017-06-16T23:52:16.172504Z 0 [Note] End of list of non-natively partitioned tables 2017-06-16T23:52:16.707901Z 3 [Note] Access denied for user ‘root’@‘localhost’ (using password: NO)

Watching htop has been helpful. Occasionally I will see spikes in memory and CPU usage to 100%. Unfortunately, I have no idea what I’m looking at or should be looking for.

Hi @semipro

Try installing htop which gives you detailed information about all processes real-time:

sudo apt install htop

Is the site on the $10 using the same theme and plugins as the $5 sites? A single heavy or badly coded theme/plugin can even make a $80 droplet go to a crawl.