PDA

View Full Version : Problem Running 'mysqldump()'


Len_Jacobson
8-20-09, 10:49 PM
I am trying to manage my own backup of the database via a PHP script. That is, I want it to be an automated process rather than a manual process.

The following is a snippet of code to execute 'mysqldump()' on my database:



if (system("mysqldump -u " . $superUser . " -p" . $superPassword . " [name of database] > $fullPath") !== false)
echo "<p>Database backed up to '" . $fileName . "'</p>";
else
echo "<p>Error backing up database</p>";



This code works perfectly fine on either of my two test servers (running Windows Vista), but doesn't produce any output when run on the PowWeb.com web server. Interestingly, it also does not display my "Error backing up database" message. Instead, it displays the "Database backed up to ..." message.

I would like to be able to test the 'mysqldump()' command directly in an SSH session window, but PowWeb.com doesn't allow such a connection. So I can't see if that produces an error.

But on GoDaddy.com, I can open an SSH session window and run the command. When I do that on GoDaddy.com, it does produce the following error:


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


Obviously, I can't be certain that the <<name removed>> error message is applicable to what is happening on the PowWeb.com web server, but my gut tells me it is.

Can anyone please offer any suggestion as to why I can't run the 'mysqldump()' successfully? Again, it does work perfectly well on both of my test servers (running Windows Vista).

Thank you.

YvetteKuhns
8-21-09, 04:20 PM
I still think your php script times out as I mentioned in the other thread. The script must be completed in 60 seconds. BigDump (http://www.ozerov.de/bigdump.php) executes part of a backup, then restarts where it last stopped to complete the task. You can run a cron job to automate running this script.

Len_Jacobson
8-21-09, 06:46 PM
Thank you, YvetteKuhns, for trying to help me here. But timing out is not the problem. When I run my code with only the code for the 'mysqldump()', the result is still the same (viz., no output file produced, and yet the 'system()' command that runs the 'mysqldump()' command returns SUCCESS).

And this takes less than one second to run.

By the way, you mention using 'cron' to run the script. Can you please tell me the cron syntax for executing a PHP script on my website?

Thanks much.

HalfaBee
8-21-09, 07:07 PM
If you read the www.php.net/system page the returned value is the last line of output, not the status.

YvetteKuhns
8-21-09, 08:29 PM
CRON: Configuring the Scheduled Jobs tab for a PHP script on PowWeb (http://forums.powweb.com/showthread.php?t=81481)

Try getting the php script I suggested to run. It is known to work here. If it works, try it with a cron job. If that works, then you can continue to troubleshoot your own script knowing what does work here.

Len_Jacobson
8-22-09, 12:44 PM
Response to HalfaBee:

Yes, I did see that the return value from the 'system()' command was the last line of output [from the 'mysqldump()' command]. But if the 'system()' command failed, then the return value was 'false'. So I then modified my call to 'system()' so that I used the second (optional) parameter, the one that gives you the return value issued by the 'mysqldump()', itself. That return value is "2", so that tells me that something is definitely wrong in what I am doing.

But I can't find anywhere what the return value of "2" means? Not even Sun's manual on 'mysqldump()' tells you what the return values are.

Len_Jacobson
8-22-09, 02:03 PM
Response to YvetteKuhns:

Thank you for the reference on CRON. I will open a new thread on this topic.

Len_Jacobson
8-22-09, 02:07 PM
While playing around with trying to schedule a job, the "Scheduled Jobs Log" had an entry in it that suggests that the return value of "2" implied the exact same error message that I got when running the 'mysqldump()' on GoDaddy.com, inside an SSH session window. That is, the return value 2 does, in fact, mean:


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


Can anyone please suggest how I might get passed this error?

HalfaBee
8-22-09, 07:42 PM
You can't access Powweb databases from an external server.

You need to specify the server using

<manual>
--host=host_name, -h host_name

Dump data from the MySQL server on the given host. The default host is localhost.

Len_Jacobson
8-22-09, 08:20 PM
Please bear with me -- I do not understand what you wrote.

Are you saying that I can only dump the contents of a database by manually dumping it, say, through the "Manage MySQL" web page?

What do you mean by "<manual>"?

HalfaBee
8-23-09, 12:28 AM
It was an excerpt from the mysql manual.

You need to add --host=opsusername.powwebmysql.com to the mysqldump command.

Len_Jacobson
8-23-09, 01:20 AM
HalfaBee -- Thank you, thank you, thank you!! Adding the hostname parameter to the 'mysqldump()' command was exactly what I needed. It works!!

Please tell me how I can indicate that this thread is "complete, solved".

HalfaBee
8-23-09, 03:25 AM
There is no technical way to do it.
A Moderator will probably close the thread.

IanS
8-23-09, 05:05 AM
He will - glad the problem was solved.