• My wordpress site is running on an EC2 instance. The WP database is running on AWS MySQL RDS.
    I got the alert a while back that the SSL CA was changing for RDS. But since I didn’t think I was communicating via SSL I didn’t have to change anything.

    Then yesterday I noticed we were having a database issue, so I thought it was related to the SSL updates. So I tried upgrading our current DB to the 2019 CA with no luck. So I spun up a NEW MySQL RDS instance using the same DB name, username, & password. I exported the data from the original DB and imported it to the new DB.

    I made the change to the hostname in the wp-config.php file. Confirmed I was able to connect. All good.

    Seemed like we were ok for a bit. But the issue is intermittent. My website loads but I think it’s pulling from the cached CDN… and I’m too worried to clear the cache in fear of taking the whole site down. But when I go to the /wp-admin page it sometimes does load, and I can login just fine. Most times I get wordpress error: Error establishing a database connection.

    I also sometimes get an error just going to the website that a database connection cannot be made.

    So my config looks right and honestly nothing has changed in months. So it doesn’t seem like a WP issue. But more of a hardware or connection issue?

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mattwiner

    (@mattwiner)

    So this is even more weird now. The connection to the DB is very intermittent.
    I created a very simple test connection script. When I refresh it. 30-40% of the time I get “Could not connect”

    <?php
    $link = mysqli_connect('wpdb.xxxxxxx.amazonaws.com', 'username', 'pass');
    if (!$link) {
    die('Could not connect: ' . mysqli_error());
    }
    echo 'Connected successfully';
    mysqli_close($link);
    ?>

    Did Amazon tell you it was a WordPress issue when you called them?

    I really can’t think of anything in WordPress causing an intermittent database connectivity problem.

    Thread Starter mattwiner

    (@mattwiner)

    I haven’t heard back from Amazon yet. But another issue I was having was I was running out of memory. The server has 4GB of RAM and it was telling me in the error log that I was running out of memory.

    So I upgraded the memory so I could actually work on the system a bit. But after running a netstat I see I have over 900 connections from my localhost!!!

    According to my google analytics I have 0-1 person on the site, my database has > 140 connections and all these users.

    I thought it was a ddos attack, but it’s coming from inside, not out.

    netstat -ant | awk ‘{print $5}’ | cut -d”:” -f1 | sort | uniq -c | sort -nr

    906 127.0.0.1
    567 172.31.26.136
    206
    4 0.0.0.0
    3 54.84.127.13
    2 52.202.74.172
    2 173.165.202.202
    1 and
    1 Address

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP Losing Connection to DB’ is closed to new replies.