473,498 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP, MySQL and crontab

I have a PHP cli script, that backups my databases, using mysqldump
via system().

When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I put it in a crontab:

00 2 * * * /home/sandman/bin/backup.php

I get a mail that says:

"mysqldump: Got error: 2002: Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (2) when trying to
connect"

How come? Anyone knows what the difference is between CLI and crontab
that could cause this?

--
Sandman[.net]
Sep 6 '06 #1
3 3360
Sandman wrote:
I have a PHP cli script, that backups my databases, using mysqldump
via system().

When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I put it in a crontab:

00 2 * * * /home/sandman/bin/backup.php

I get a mail that says:

"mysqldump: Got error: 2002: Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (2) when trying to
connect"

How come? Anyone knows what the difference is between CLI and crontab
that could cause this?
Well, for one thing, what's the user you have set up for your cron job?
Does it have permission to use the socket? Is it using the correct
socket?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 6 '06 #2
In article <9f******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:
I have a PHP cli script, that backups my databases, using mysqldump
via system().

When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I put it in a crontab:

00 2 * * * /home/sandman/bin/backup.php

I get a mail that says:

"mysqldump: Got error: 2002: Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (2) when trying to
connect"

How come? Anyone knows what the difference is between CLI and crontab
that could cause this?

Well, for one thing, what's the user you have set up for your cron job?
The same user I'm executing it with when it's working.
Does it have permission to use the socket? Is it using the correct
socket?
Well, after looking, the socket "/var/run/mysqld/mysqld.sock" doesn't
seem to exist. I realize I should have checked that first, but since
it worked before, I assumed that wasn't the problem.

There DOES exist a /tmp/mysql.sock file, and I have now set up my PHP
script with "mysqldump -S /tmp/mysql.sock" and I'll see in the morning
if it throws the same errors.

But how come mysqldump finds a correct socket when I'm running it from
the shell but not when I'm running it through crontab?
--
Sandman[.net]
Sep 6 '06 #3
Sandman wrote:
In article <9f******************************@comcast.com>,
Jerry Stuckle <js*******@attglobal.netwrote:

>>>I have a PHP cli script, that backups my databases, using mysqldump
via system().

When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I put it in a crontab:

00 2 * * * /home/sandman/bin/backup.php

I get a mail that says:

"mysqldump: Got error: 2002: Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (2) when trying to
connect"

How come? Anyone knows what the difference is between CLI and crontab
that could cause this?

Well, for one thing, what's the user you have set up for your cron job?


The same user I'm executing it with when it's working.

>>Does it have permission to use the socket? Is it using the correct
socket?


Well, after looking, the socket "/var/run/mysqld/mysqld.sock" doesn't
seem to exist. I realize I should have checked that first, but since
it worked before, I assumed that wasn't the problem.

There DOES exist a /tmp/mysql.sock file, and I have now set up my PHP
script with "mysqldump -S /tmp/mysql.sock" and I'll see in the morning
if it throws the same errors.

But how come mysqldump finds a correct socket when I'm running it from
the shell but not when I'm running it through crontab?

Is it possible you have two copies of mysqldump on your system? The
cron job is probably running as a different user - and therefore would
have a different profile, among other things.

Or maybe it's picking up a different my.ini file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3527
by: Arkascha | last post by:
Maybe someone can give me a short help with this... I got a server application in a LAMP environment doing batch tasks. A cronjob serves as a regular trigger, a metronom. The trigged...
3
5344
by: Frank R. Suchy | last post by:
Hi, I want a php-script to maintain (some of) "my" cron jobs. Therefore it has to modify some crontab.txt (no problem) and has to execute crontab. But since php runs as the apache-user it...
1
2153
by: Solange Ezveff | last post by:
Hi, Trying to restart MySQL when it is down. I have placed the following script in a file : checksql ---> #!/bin/sh /etc/rc.d/init.d/mysqld status >/dev/null 2>&1
3
5384
by: rbt | last post by:
How can I safely append a crontab entry to a crontab file progammatically with Python? I need to handle crontabs that currently have entries and crontabs that are empty. Also, I'd like this to...
2
8409
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even...
3
10287
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the...
3
2567
by: dburdick | last post by:
I was referred to this forum as this may be a php specific problem. Some kind of configuration problem maybe. I have some php files that connect to a mysql database and are run as cron jobs. ...
4
7100
by: Bob | last post by:
Hi, I would like to periodically start and stop mysql on a schedule using something like the Windows scheduler. Does anyone know a good way to do this? Thanks, Bob
4
3953
by: Chr1s | last post by:
How do I execute a crontab command using php (not CLI) as user Joe? I don't have any problem getting output from commands such as 'ls' using passthru and exec but I am stumped with crontab. ...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.