Getting Wordpress Database error on daily bases at digital ocean

Hello,

I need help regarding database error. I am using a digital ocean with an easy engine for WordPress. Everything was fine and the site is the same no plugin added or removed since last year.
But now when I visit the homepage it shows

Error establishing a database connection

While visiting the wp-admin panel it shows.

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at global-db:3306 . This could mean your host’s database server is down.

The only solution which I have is either restart my digital ocean droplet or use the ssh command to restart the database. But I need a permanent fix. Bcz sometimes the site goes down twice a day. I checked all CPU, storage, and bandwidth usage everything is normal.

Please check at here https://safetricks.org/

How can I find our problem?

Thanks in advanced

Check if database container is running or not with:

docker container ls

DB container NAME will be services_global-db_1

If DB container isn’t running or in restart loop,

  1. Check if disk is not full. Command: df -h /
  2. Check if docker container/s are running or not. Command: docker container ls
  3. Check if running MySQL command with hostname, username and password from PHP container(or ee shell site-name.tld) is working or not.
  4. Check the logs of DB container. Command: docker logs services_global-db_1
    You can use the following command to get MySQL access
# access as root:
docker-compose -f /opt/easyengine/services/docker-compose.yml exec global-db bash -c 'mysql -uroot -p${MYSQL_ROOT_PASSWORD}'

This command will give you access of MySQL shell as root user.
You can access MySQL docker container shell with following command

docker exec -it services_global-db_1 bash

The reason for this can be multiple.

I have had this issue on the $5 droplets on DO as well. There are two fixes that have worked for me and proven to be reliable fixes.

PROBLEM: Mysql container is killed and when listing docker containers (docker ps) you see the mysql container perpetually restarting. Also checking the system logs surfaces error messages that essentially indicate that the droplet is running out of memory and the most memory intensive containers will be killed. That is always the mysql container.

EASY FIX: In 100% of the cases for me, I upgrade the container from a $5 to a $10 month container, making sure to select the configuration that effectively doubles your RAM memory. Problems solved. But of course, that will cost you more per month.

CONFIGURATION FIX (a bit harder): For those droplets where i just don’t feel like I wish to expend the extra money per month, like low traffic affiliate sites, I wound up taking the relevant parts of this article https://easyengine.io/docs/prevent-mysql-crashing/ and this Github issue https://github.com/EasyEngine/easyengine/issues/791 and made the configuration changes manually. I have to check to make sure those changes stick after upgrades and updates but since I placed the files in the recommended global folder /opt/easyengine/services/mariadb/conf/conf.d/ I have not seen any of my modifications change.

If you prefer to run a well known script to get some optimized settings, check out https://easyengine.io/handbook/how-to-use-mysqltuner-with-ee4/ and ticker with mysqltuner. I have used this perl script many times on larger traffic systems, but rarely mess with it on smaller sites. it just seems easier to mess with the max_connections and the various timeouts manually. Sometimes the output from mysqltuner gets a bit involved and can actually cause more issues if you do not know what the settings actually do to the site.

1 Like

Did you ever resolve your database connection issue?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.