I want to create a backup from a database, but I get only a blank file.
include('config.php');
$command = "mysqldump --opt -h ".$_host." -u ".$_user." -p ".$_pass." ".$_db." > test.sql";
exec($command);
echo "<br />".$command;
test.sql is created where the .php file is located.
Edit:
Note! I'm using XAMPP WINDOWS !
Solution:
Because I'm using a Windows Web Server (XAMPP), I needed to specify the path:
$command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql';
-pMYPASSWORD
"
with '
I think if you are using a Linux based web server, you don't have to specify the path for mysqldump.
Cheers! :-)
It dumps one or more MySQL databases for backup or transfer to another SQL server. The mysqldump command can also generate output in CSV, other delimited text, or XML format.
Mysqldump is a command-line utility that is used to generate the logical backup of the MySQL database. It produces the SQL Statements that can be used to recreate the database objects and data. The command can also be used to generate the output in the XML, delimited text, or CSV format.
INTO DUMPFILE is a SELECT clause which writes the resultset into a single unformatted row, without any separators, in a file. The results will not be returned to the client. file_path can be an absolute path, or a relative path starting from the data directory.
mysqldump can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it. Buffering in memory can be a problem if you are dumping large tables. To dump tables row by row, use the --quick option (or --opt , which enables --quick ).
Try this one:
$command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql 2>&1';
-its about permission issue.
These are the parameters
-uROOT -pPASSWORD --databases DB --result-file=FILE.SQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With