Blog cron job: connection to mysql database fails

Tags: mod_secMySQLpassword reset

Published on: September 26, 2014 by Felix cron job: connection to mysql database fails


The cronjob producing the following database connection error


DBI connect('modsec:localhost','modsec',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at /etc/cron.hourly/ line 19

Unable to connect to mysql database at /etc/cron.hourly/ line 19.


Try reproducing the error by running the cron job manually:


If it shows the same error, make sure the password used on the “my $dbpassword” 19th line in /etc/cron.hourly/ matches the “modsec” password in MySQL.

my $dbpassword = ‘sample’;

You can reset the “modsec” MySQL password by following these steps:

    mysql > use modsec;
    mysql> update user set Password=password('sample') where User='modsec';
    mysql > flush privileges;
    mysql> quit;


Also in WHM Click Service Manager -> Check enable mysql and mysql monitor boxes -> Save changes. It should solve problem.


Get 24/7 expert server management

Category : Howtos, MySQL, Troubleshooting



Firaz has been in the Web Hosting industry since 2012. He is always fascinated in resolving complicated DNS, cPanel and other Web hosting issues. He loves to help newbies to climb the hill from a fresher to an experienced System admin. Movies and songs are his favourite passtime.

You may also read:


Add new commentSIGN IN

Let's Connect

Get new updates


$0.000 items