Title: Database sometimes error
Last modified: August 15, 2023

---

# Database sometimes error

 *  [robotx](https://wordpress.org/support/users/robotx/)
 * (@robotx)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdatabase-sometimes-error%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [hosein79](https://wordpress.org/support/users/hosein79/)
 * (@hosein79)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/database-sometimes-error/#post-16973765)
 * 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:
 *     ```wp-block-code
       systemctl status mariadb
       ```
   
 * If MariaDB is not running, you can start it using:
 *     ```wp-block-code
       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](https://wordpress.org/support/users/robotx/)
 * (@robotx)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/database-sometimes-error/#post-16974432)
 * 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.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [vps](https://wordpress.org/support/topic-tag/vps/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [robotx](https://wordpress.org/support/users/robotx/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/database-sometimes-error/#post-16974432)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
