1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Frequent Error establishing a database connection ec2

Discussion in 'MySQL' started by neeshu, May 14, 2018.

  1. #1
    Hi
    My website is on ec2, I have not put in any post on it still,
    I am getting the error Error establishing a database connection every 5-6 hours, I
    have to manually restart the MySQL server using the command line,
    the site is running on Ubuntu, Apache and using WordPress.

    Can you please suggest what could be the problem
    I checked the access logs there were some Russian IP's which I had blocked
    then I had also checked the CPU usage on AWS which rarely reached 100% usually it was
    in range of 30-40%

    Regards
     
    neeshu, May 14, 2018 IP
  2. SpacePhoenix

    SpacePhoenix Well-Known Member

    Messages:
    196
    Likes Received:
    28
    Best Answers:
    2
    Trophy Points:
    155
    #2
    Do you have any cron jobs that run every 5-6 hours?
     
    SpacePhoenix, May 15, 2018 IP
    neeshu likes this.
  3. neeshu

    neeshu Well-Known Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    neeshu, May 15, 2018 IP
  4. Komputerking

    Komputerking Greenhorn

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    8
    #4
    For a wordpress website like this, unless you need cron to run every few minutes, you are better off changing wordpress to run cron manually.

    You can add this to wp-config.php

    define('DISABLE_WP_CRON', true);

    and then add a cronjob to perform cron manually. Generally, you can allow wordpress to run once a day. Here is a script I use on small sites to automatically update cron to run randomly once a day (so that not all sites try to run cron at the same time and cause DB issues)

    crontab -u [user] -l > mycron
    echo -e "$((( RANDOM % 60 ))) $((( RANDOM % 24 ))) * * *\t/usr/local/bin/php /home/[user]/public_html/wp-cron.php > /dev/null 2>&1" >> mycron
    crontab -u [user] mycron
    rm -f mycron

    Depending on your servers configuration, the path to php may be different, and you will need to update the path to wp-cron.php, but that should do the trick.

    Also, if your site is getting bombarded by fake users, then you will want to do the following as well...

    Add these modifications to your .htaccess file.

    <files wp-config.php>
    order allow,deny
    deny from all
    </files>

    <files xmlrpc.php>
    order allow,deny
    deny from all
    </files>

    A lot of bots will attempt to abuse the xmlrpc.php file, and this will deny their access. If you need it for any reason, you can whitelist the servers ip.

    Lastly, you most likely do not have wp-admin/wp-login.php locked down. I recommend installed math captcha, or some sort of captcha server. Additionally, you can lock down the wp-admin directory entirely by ip, if necessary. That's a bit more configuration, and you will want a VPN you regularly use and whitelist so that you can always access your server.

    Also, when was the last time you tuned your database? You may want to check the processlist on it, and also set the mysql connection timeouts low, to something like 60 seconds, if you are getting hammered. You may be running out of connections, as they are not releasing.
     
    Komputerking, Jul 31, 2018 IP