views:

329

answers:

2

I am using MySql 5.1 Database.

I have created a Project database. (Temnplate Database)

and want to Create a copy of the same database from the Application, every time, User Creates A new Project.

How can I copy and Create a New Database of same structure.??

What is the Command to do so???

Thanks a Lot for Help.

+1  A: 

Dump the database with the -d option.

To create a new copy, do a "create database new-database-name; use new-data-base-name;", then run the dump file as a sql script.

tpdi
How can I do the same?? can we copy n create a new structure with single command??
Ashok Gupta
No. In fact the dump file will issue one command per structure (table, view, sp, index, etc.).
tpdi
+1  A: 

If you only want to copy the table structure etc. from one db to the other you can use this single bash line:

mysqldump -u user -ppass -d olddb | mysql -u user -ppass -Dnewdb

The new database must exist already. The -d flag in the mysqldump command prevents copying of data.

Peter Smit