The mysqldump command has a lot of options, but minimally you might type something like this into a terminal window:
mysqldump my_database > my_database_dump.sql
That command will dump the contents of the database named 'my_database' into a file named my_database_dump.sql in the current working directory. It assumes that you have permission to do so and that the db server is localhost. If you need to specify a username or password to gain access to the db, you can do that. You can also specify a dump from an entirely different machine. read the docs for more info.
A PHP example that would use this command might work like this:
$command_output = array(); // this var will contain the server's response to your command
$result = NULL; // this var should contain zero i think if all goes well
exec("mysqldump my_database > /path/to/my_db_dump.sql", $command_output, $result);
if ($result !== 0) {
echo 'Dump command failed!<br>';
} else {
echo 'success!';
}
print_r($command_output);
NOTE: You may need to specify the full path to the mysqldump binary depending on how your server is set up. On the CentOS and Debian machines I've dealt with, you can usually just type 'mysqldump' and it works, but on the Mac I use for development, I must type the full path to mysql. Here's an example that lets me dump a remote db (at somedomain.com) to the local mac. i can specify a host, a port, user, pass, etc.
/applications/mamp/Library/bin/mysqldump -h somedomain.com -P 3308 -u myuser -p'here_is_my_password' --compress my_database > my_db_dump.sql