Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php exec() - mysqldump creates an empty file

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';
  1. I removed the space between the -p and the pass. It looks like: -pMYPASSWORD
  2. Replaced " with '

I think if you are using a Linux based web server, you don't have to specify the path for mysqldump.

Cheers! :-)

like image 795
Reteras Remus Avatar asked Aug 17 '12 10:08

Reteras Remus


People also ask

What is the output of Mysqldump?

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.

Does Mysqldump include data?

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.

What is Dumpfile in MySQL?

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.

Does Mysqldump drop table?

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 ).


2 Answers

Try this one:

$command = 'd:\xampp\mysql\bin\mysqldump --opt -u '.$_user.' -p'.$_pass.' '.$_db.' > test.sql 2>&1';

-its about permission issue.

like image 181
javinczki Avatar answered Nov 09 '22 14:11

javinczki


These are the parameters

-uROOT -pPASSWORD --databases DB --result-file=FILE.SQL

like image 4
Jordi Kroon Avatar answered Nov 09 '22 15:11

Jordi Kroon