Saturday, April 30, 2011

Copy Database Sructure of Mysql Database.

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.

From stackoverflow
  • 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.

    Ashok Gupta : How can I do the same?? can we copy n create a new structure with single command??
    tpdi : No. In fact the dump file will issue one command per structure (table, view, sp, index, etc.).
  • 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.

0 comments:

Post a Comment