Forum Moderators: open

Message Too Old, No Replies

MySql - Creating Prepopulated Table

         

juicytuna

3:49 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



I have a table with over 100 rows which I'd like to be able to recreate on other servers. Using create_table and manually entering each row as an argument will take a long time as you can imagine. Is there a quick way for generating a prepopulated create_table statement for on an already existing table?

Thanks.

phranque

12:00 am on Oct 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the CREATE TABLE statement does not have a syntax for inserting rows into the table.
if you want to duplicate an existing table from one database in another database i would suggest using mysqldump:
first:
mysqldump -uuser -ppassword olddatabase table >olddatabase_table.sql
(where user, password, olddatabase and table are replaced with actual names/values)
olddatabase_table.sql will contain among other statements a suitable CREATE TABLE statement and a series of INSERT statements to reproduce the existing table with its contents.
then:
mysql -uuser -ppassword newdatabase <olddatabase_table.sql