3

I am using MySql 5.1 Database.

I have created a Project database. (Template 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?

3 Answers 3

18

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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

Check out the SHOW CREATE TABLE command: https://dev.mysql.com/doc/refman/5.0/en/show-create-table.html It will return the create command used to create the given table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.