Copying DB1 as DB2

I have a database named “DB1”.
DB1 has some tables and each table has some records each.
I like to copy DB1 as DB2 with all tables and all records.

We need the db engine you are working with :slight_smile:

Sorry, I am using MySQL.

dump DB1 to sql file, alter the CREATE DATABASE statement, and run

There is also the CREATE LIKE route.

CREATE db2.newtable LIKE db1.oldtable

This will copy the structure, then you can run an insert…


INSERT INTO db2.newtable
SELECT * FROM db1.oldtable

You would then just need a way to iterate through the result set of all tables in db1 and run the queries.


SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'db1'

kyle, your method involves way more work :wink:

I’m providing another option. We don’t know his use case. He may find it more suitable for his needs. In any case, it is an option…

:wink:

I used to copy the DB1 folder and rename it as DB2 using the computer which is the web/database server.
Now I like to copy DB1 in a remote place through internet in PHP.
Can I dump it at a remote place?

i don’t see why not

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html