Cron Job unable to access MySQL Database when host is set to localhost

leland

Member
Jan 7, 2011
10
0
51
I have some cron jobs that suddenly stopped a few days ago. I traced it back to the host setting when connecting to the database. When I use localhost, the script fails giving me this error: 'Error establishing mySQL database connection. Correct user/password? Correct hostname? Database server running?'. When I use the server's IP address or 127.0.0.1, the script works as it should.

Also, this only seems to be happening to one account and if I were to access the script through a browser and the host is set to 'localhost' the script works fine.

What could cause localhost to not work only for crons and for only one account?

Running:
CENTOS 6.3 x86_64 standard
WHM 11.38.0 (build 19)
 

leland

Member
Jan 7, 2011
10
0
51
Ya, I did move the database to a different mount. I will try it our. Thank you for the suggestion.
 

patchwork

Well-Known Member
Nov 2, 2001
95
0
316
I've got a lot of crons running in each account, I've just added a new job and all of a sudden all the crons for that account have suddenly all stopped working and giving the mysql connection problem.

MYSQL is on a separate drive and has been for a long time, why would adding a new cronjob all of a sudden cause all the crons in that account to start failing?

The crons in other accounts are still fine.

- - - Updated - - -

I've created /var/cpanel/jailshell-additional-mounts and added the mysql data directory path to it, and it seems to have fixed it.

This seems like its a bug in cpanel that should be checked and fixed by upcp
 

ksaied

Member
Dec 7, 2007
10
0
51
cPanel Access Level
Root Administrator
Dear Sir,

i use the following symlink

/var/lib/mysql -> /home/mysqldata/

What should i write in /var/cpanel/jailshell-additional-mounts ??

Regards,
 
Last edited:

ksaied

Member
Dec 7, 2007
10
0
51
cPanel Access Level
Root Administrator
Dear Sir,

Not working.

I moved /var/lib/mysql -> /home/mysqldata from about 6 months but didn't test cronjobs.

This is strange, localhost in mysql_connect is working when executed from the web or from shell as root but not in cronjobs.

I receive the following error only with cronjobs:

mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

127.0.0.1 is working, but i don't want to change the code of all my clients.

What should i do to make localhost work with cronjobs.

Kindly send me detailed steps.

Thanks,
 

ksaied

Member
Dec 7, 2007
10
0
51
cPanel Access Level
Root Administrator
Yes i made the step of putting (/home/mysqldata) in /var/cpanel/jailshell-additional-mounts

[mysqld]
datadir=/home/mysqldata/
socket=/home/mysqldata/mysql.sock
interactive_timeout=120
max_user_connections=70
table_open_cache=400
event_scheduler=on
open_files_limit=16000
max_allowed_packet=268435456
query_cache_limit=1M
innodb_file_per_table=1
thread_cache_size=4
innodb_buffer_pool_size=210M
wait_timeout=28800
query_cache_size=32M
max_connections=600
query_cache_type=1
default-storage-engine=MyISAM
[client]
socket=/home/mysqldata/mysql.sock
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,234
363
cPanel Access Level
DataCenter Provider
Twitter
Feel free to open a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

Thank you.