1

Is there any application that will read a MySQL database table and generate a SQL script of INSERT statements (so that I can copy tables from one db to another db)? OR how can I transfer content from db1.table1 to db2.table2 where table1 and table2 is same.

Thank you.

2 Answers 2

5
mysqldump [options] db_name [tbl_name ...]

Will generate the script file including the create and inserts necessary for the tables selected. To import the dump you can simply do:

mysql -u <user> -p dbname < mys.dmp
Sign up to request clarification or add additional context in comments.

3 Comments

Could you let me know how can I specify DB host and port?
mysql (or mysqldump) -h <host> -P <port> Thanks for the point and answer!
It worked. Thank you. The only point I would like to add is this: mysqldump use only one INSERT statement while creating the script. Using --skip-opt will create each INSERT statement separately.
3

You should take a look at mysqldump. You can specify the --nodata option to export the schema only.

1 Comment

mysqldump -u user -p database_name --no-data > output_file.sql

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.