cPanel Cron job commands can't connect to Database ?!

jasonsmit

Member
Jan 15, 2013
7
0
1
cPanel Access Level
Root Administrator
Hello,

I have receiving this following error messages from cpanel running hourly and daily Cronjobs :

---------------------
error massege:
PHP Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock

or
Critical Error : Could not connect to the database

or

ERROR OUTPUT:
mysqldump: Got error: 1045: Access denied for user '***_user'@'localhost' (using password: YES) when trying to connect

or ......


---------------------

Note: my script can connect to database and mysql fine and no problem there ! and when running these command on root crons haven't problem and running fine there ,

But php script command can not connect to database correctly under cpanel end user (normal account user) CronJobs, and send me that error messages,

Please help me to fix ,

Thanks to all
 

Scriptking

Registered
Oct 10, 2014
4
0
1
Newcastle, New South Wales, Australia
cPanel Access Level
Root Administrator
im having same issue, every day i wake up to sql server turned off... i need to login to WHM and re-start it.. its a real pain..

this is the error i wake up to every day..

/etc/cron.hourly/modsecparse.pl:

DBI connect('modsec:localhost','modsec',...) failed: Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 104 at /etc/cron.hourly/modsecparse.pl line 20
Unable to connect to mysql database at /etc/cron.hourly/modsecparse.pl line 20.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,222
463
Hello :)

Check to see if the /tmp/mysql.sock symbolic link exists:

Code:
ll /tmp/mysql.sock
If not, create it via:

Code:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,222
463
It's likely a limitation of the jailed shell/noshell access applied to the account. Do you experience the same issue when the account is assigned normal shell access?

Thank you.