Support » Fixing WordPress » Database sometimes error

  • Hello can anybody help me,
    why my site sometimes going down with error message

    “error establishing a database connection, Connection Refused”

    I have develop many websites using WordPress and this is my first error,

    I use Vps base on Ubuntu 20.4, OpenLiteSpeed, MariaDB & php 7.4

    thanks

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Certainly, I’d be happy to help you troubleshoot the “error establishing a database connection” issue on your WordPress site. This error typically occurs when your WordPress site cannot connect to the database server. Here are some steps you can take to diagnose and potentially fix the issue:

    1. Check Database Credentials: Ensure that your WordPress site’s wp-config.php file contains the correct database credentials, including the database name, username, password, and database host (usually localhost or 127.0.0.1). Double-check these details to make sure there are no typos.
    2. Database Server Status: Verify that your MariaDB database server is running and responsive. You can do this by logging into your VPS via SSH and running the following command:
    systemctl status mariadb
    

    If MariaDB is not running, you can start it using:

    sudo systemctl start mariadb
    
    1. Check Database Server Port: Make sure that the database server is listening on the expected port (default is 3306). If you have customized the database port, ensure that the port in your wp-config.php matches the one that MariaDB is configured to use.
    2. Server Load and Resource Usage: Check if your VPS is under high load or running out of resources (CPU, memory, disk space). High resource usage can lead to database connection issues. You can use commands like top or htop to monitor resource usage.
    3. Database Size: If your database has grown large, it might cause slowdowns or connection issues. Optimize and clean up your database by removing unnecessary data, optimizing tables, and ensuring proper indexing.
    4. Database User Privileges: Confirm that the database user you’re using to connect to the database has sufficient privileges to access and modify the database. You can check this in your database management tool or command-line interface.
    5. Firewall and Security Groups: Make sure that your VPS firewall and any external firewalls or security groups are not blocking the database port (usually 3306). Check both inbound and outbound rules.
    6. Database Server Logs: Examine the MariaDB error logs for any relevant information. The logs might provide insight into the cause of the connection issue. The logs are often located in /var/log/mysql/ or a similar directory.
    7. WordPress Plugins/Themes: In some cases, a poorly coded plugin or theme might cause excessive database queries, leading to connection issues. Try disabling plugins or switching to a default WordPress theme to see if the problem persists.
    8. Restart Services: After making any changes, it’s a good idea to restart both the web server (OpenLiteSpeed) and the database server (MariaDB) to ensure that the changes take effect.
    9. Testing Connection: You can also try connecting to the database using command-line tools like mysql from your VPS to see if you can establish a connection manually.

    If you’ve tried these steps and still encounter the issue, consider seeking assistance from web hosting or server administration professionals who can provide more specific guidance based on your server setup and configuration.

    Thread Starter robotx

    (@robotx)

    thanks for suggestion, I will try it all

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Database sometimes error’ is closed to new replies.