I have a base set of data held in a database on my server. When a user signs up for my service, I want to be able to copy this database to another database that has been created. Is there a simple and effective way to do this using PHP / MySQL? Pure MySQL would be preferable.
I thought about looping through all the tables in the base database but I wouldn’t know how to then create that table with columns to the new database.
Running PHP 5.1 and MySQL 5.
Thanks.
Here is an article with ten ways to back up a database and restore it. Each uses a different method, most of which probably work in your situation but a few apply:
http://www.noupe.com/how-tos/10-ways-to-automatically-manually-backup-mysql-database.html
Number six talks about creating a dump file and then restoring it again. You could use this to dump the data out and then you could restore it to the new database.
The other option here would be to make a physical copy of the databases. If you are storing the databases in different locations, this might be an option. It wouldn’t be quite this simple but it should work fine.
Finally, you could run a script from PHP that would do the MySql dump command for you. This would allow you to copy the entire database and set it up somewhere new so you wouldn’t even have to have a database in place yet to accomplish this:
MySQL to MySQL clone with PHP