Mysqldump create empty sql file? [php & mysql on Windows]

女生的网名这么多〃 提交于 2019-12-24 00:40:05

问题


I tried to dump a database:

<?php
$dbhost = "localhost";
$dbuser = "XXXX";
$dbpass = "XXXXXXXX";
$dbname = 'testdb';

$list = shell_exec ("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe $dbname  --user=$dbuser--password=$dbpass > dumpfile.sql");
?>

I tried both specified full path to mysqldump.exe or just use mysqldump, it still give me a 0kb dumpfile.sql

Details: Programming Language: PHP Database: MySql 5.XX OS(server): Windows Server 2003. (currently testing on Windows Vista machine)

EDIT @ Jeremy Heslop:

I tried:

shell_exec("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe --opt -h $dbhost -u$dbuser -p$dbpass $dbname > test.sql");

safe_mode = off

Still no luck man.


回答1:


Call me crazy, but don't you need to escape those backslashes in your path name? I'm guessing that the command fails, and since the error is on stderr, nothing gets written.




回答2:


It should be "c:\wamp\bin\mysql\mysql5.1.36\bin>mysqldump -u root -p zencartdb > zencartdb.sql"

it demands for password, provide if you have given password to root or simply hit enter. This will take backup successfully. I have tested it on Windows Vista also.




回答3:


If I'm not mistaken the dbname should be at the end of the call after the --user and --password like this:

$list = shell_exec ("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe --user=$dbhost --password=$dbpass $dbname > dumpfile.sql");

Otherwise if that doesn't work there are some other things to look out for. Make sure the user that php runs as has permissions to write to that directory. Also make sure that php.ini has safe_mode = off as that could cause issues. Good luck!




回答4:


I tried like this $result = system ("C:\wamp\mysql\bin\mysql.exe -u $username -p $password $dbname < $pathtomysqlfile"); and executed successfully then backup is restored.I'm wsing wamp.please try it..........



来源:https://stackoverflow.com/questions/2061922/mysqldump-create-empty-sql-file-php-mysql-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!