Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty files generated from running `mysqldump` using PHP

Tags:

php

mysql

I keep getting empty files generated from running

$command = 'mysqldump --opt -h localhost -u username -p \'password\' dbname > \'backup 2009-04-15 09-57-13.sql\'';

command($command);

Anyone know what might be causing this? My password has strange characters in it, but works fine with connecting to the db.

I've ran exec($command, $return) and outputted the $return array and it is finding the command. I've also ran it with mysqldump > file.sql and the file contains

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

So it would seem like the command is working.

like image 700
alex Avatar asked Apr 15 '09 00:04

alex


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.

Where do Mysqldump files go?

db_backup. sql is automatically generated by the mysqldump command, and is located in the current directory ( . ) by default. If you need to specify a directory, you can directly specify /path/to/target/db_backup.

Why Mysqldump is not working?

If mysqldump is not identified by the cmd prompt that means it cannot recognize where the mysqldump.exe is located. You need to add path of the directory where the exe is located in the PATH variable under environment variables. After doing that your command will start working in the cmd prompt.


1 Answers

Remove the space between -p and the password. If it didn't work, try to remove the quotes from the password

from MySQL documentation:

If you use the short option form (-p), you cannot have a space between the option and the password.

however, it is fine to have space with -h and -u options

like image 191
Aziz Avatar answered Oct 17 '22 08:10

Aziz