Page 1 of 1
Automatic database backup using mysqldump
Posted: Sat Dec 25, 2010 6:08 am
by amplifire
Hello everyone
I referred to you for database backup using mysqldump ans system() function to execute it.
So far iam able to create backup file, but my backup file is empty. When i use mysqldump from command line, it works.
But from php it doesnt work what could be the problem?
Here's my code:
Code: Select all
if($_POST['backup'])
{
$command="mysqldump -h localhost -u root myDatabase > database/backup.sql";
system($command);
echo "<script>alert('table has been copied');</script>";
}
Re: Automatic database backup using mysqldump
Posted: Sat Dec 25, 2010 7:02 am
by VladSun
You need to supply password:
Code: Select all
mysqldump -h localhost -uroot -pXXXXXX myDatabase > database/backup.sql
also use absolute paths:
Code: Select all
/path/to/mysqldump -h localhost -uroot -pXXXXXX myDatabase > /path/database/backup.sql
Re: Automatic database backup using mysqldump
Posted: Mon Dec 27, 2010 9:57 pm
by amplifire
My password is blank, so i did not supply the password. Moreover i have globaly registered the environment variable for mysqldump and i can use it from any directory. And also the .sql is being created but its blank. but when i create it from command line it gets created successfully.
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 4:21 am
by VladSun
Try
Code: Select all
$result = `mysqldump -h localhost -uroot myDatabase 2>&1`;
echo $result;
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 5:27 am
by amplifire
Thanx for sharing different ideas. but now i will give you some more information.
1) I am using Windows XP.
2) I am using WAMP server.
3) I registered environment variable for mysqldump in Windows, so that i can run mysqldump from any directory.
4) today when i opened my Apache error log (apache_error), i noticed this
'[Sat Dec 25 18:21:08 2010] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/favicon.ico
'mysqldump' is not recognized as an internal or external command,
operable program or batch file.'.
5) It means Apache is giving this error, but when i use the Command line , it works fine.
6) What could Apache possibly have to do with judging whether mysqldump is a command or not. Windows should judge.
7) I tried running 'cmd' and 'ping localhost' from php and they worked.
This is the situation. Please send some ideas on what could be happening.
Regards
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 5:29 am
by VladSun
Well, first try using the absolute path to mysqldump as I suggested. Looks like it's not in the PATH.
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 5:51 am
by amplifire
Yeh ive even tried actual path. EX.
E:/wamp/www/file/database/backup.sql
The file is getting created but its blank, empty
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 6:03 am
by VladSun
I meant to add the absolute path to "mysqldump" executable.
E.g.:
C:/Program Files/MySQL/bin/mysqldump
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 6:06 am
by amplifire
Yes. In Wamp server the absolute path is
C:\wamp\bin\mysql\mysql5.0.51b\bin
I have added it in User variables as well as System Variables under the name PATH.
And im successful in running mysqldump from any directory from command prompt. but not using PHP.
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 6:11 am
by VladSun
VladSun wrote:Try
Code: Select all
$result = `mysqldump -h localhost -uroot myDatabase 2>&1`;
echo $result;
Did you try it?
Re: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 6:16 am
by amplifire
I tried it
it is now showing this on my browser
"Invalid File'mysqldump' is not recognized as an internal or external command, operable program or batch file."
Resolved: Automatic database backup using mysqldump
Posted: Tue Dec 28, 2010 6:34 am
by amplifire
I did it. Special thanx to VladSun.
I simply did this
$command="C:\wamp\bin\mysql\mysql5.0.51b\bin\mysqldump -h localhost -u root nigamkota > database/backup.sql";
system($command);
It means there is some problem in PATH environment variable. I will see it.
Thanx