Mysqldump help

I’ve recently switched over to Dreamhost (two days ago), and am working on making all of my scripts work on the new server. This one was written for me so I don’t understand it perfectly, this is just a snippet. BACKUPDIR is defined earlier as where I would like the backup to go. Now I’ve tried specifying the host, and I’ve tried saying a specific database instead of just the catch all databases, but that didn’t work either. Let’s assume I always want to back up all the databases, and all the tables therein. What do I do?

[php] // do we want to back up all databases?
$backupall = ($_POST[‘backupall’] == ‘false’) ? false : true;

// if we want to back up all databases, set this to -A in the command (backs up all), if not, set it to the name of the database to back up
$dbarg = $backupall ? '-A' : $_POST['backupwhichdb'];

// form our command to execute
$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -r \"".BACKUPDIR.$_POST['filename']."\" 2>&1";


This is the current version I am working on:

$command = “mysqldump -h -u “.$_POST[‘mysqluser’].” -p”.$_POST[‘mysqlpass’]." -B absurdity981_sitemap “”.BACKUPDIR.$_POST[‘filename’]."" 2>&1";

It displays all the database info in the page, instead of sending it to a new page. As well I get the error:

mysqldump: Got error: 1102: Incorrect database name ‘/home/kochier/www/’ when selecting the database at the bottom of the page.

EDIT: Also if I use -A it’ll display a list of options "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 " that I’m not sure how to utilize.

Push it out to a file.


$usr = dbusername
$psw = dbpassword
$sql = dbhostname
$aff = an optional affix, such as date()

command format:

mysqldump --opt -u $usr -p$psw -h $sql -A > $sql_$aff.sql

Thanks that helped me a lot. I just had things in the wrong order.[php]$command = “mysqldump -c -u “.$_POST[‘mysqluser’].” -p”.$_POST[‘mysqlpass’]." -h -A > “.$_POST[‘filename’].” 2>&1";[/php]

That is the final code I used.

Just FYI, you should change the subdomain that your database is hosted on because now that it’s clear what it is, anyone can attempt a dictionary attack on it by visiting

^ Good advice that everyone should consider seriously.

Big random strings using a [nonsense] sub-domain work.

Will do, thanks for the advice.