For help with MySQL management, you might want to download and try
phpMyAdmin. This will allow you to view your MySQL databases through the web. I use it all the time, it's a very handy tool. It will allow you to import and export databases.
However, php is not a great way to backup/restore databases larger than a few MB. PHP has a default execution timeout. If your backup or restore take longer than the default execution timeout, then the script will hault. If you want to modify this parameter, it can be found in the php.ini file under the variable named "max_execution_time".
To backup a MySQL database, run the following via command line from the bin directory. (or if mysql is in the path settings, just run mysqldump)
mysqldump --add-drop-table -u
[user_name] -p
[password] [database_name] >
[file_name(.extension)]
To restore a database:
mysql -u
[user_name] -p
[password] [database_name] < ./
file_name(.extension)]
**Note the direction of the
< or
> when backing up a database. I always like to think of the symbol as pointer for the direction of the flow of data.
One other caution. The argument "--add-drop-table" applied to the backup will place a statement in the backup file above each table to "drop" each table in a given database with the same name during a restore. If you DO NOT use the "--add-drop-table", AND a table already exists, then the restore will not drop the current table and may halt.
If you're not sure, ALWAYS backup the database prior to restoring just in case the restore goes sour. I prefer to add the "--add-drop-table" argument so that I don't have to worry about dropping each table prior to restoring.
If you would like a script to help automate your backups, I can send you the modified version that Mercutio wrote for me when we started this site. The script does a backup, then compresses the file with the current date and time.