I would like to combine two mysql database files (*.db) into a single database. Both databases have the same tables. Is there an easy way to do this?

  • 1
    Why on earth is this tagged as Excel and SQLite? – Jonathon Reinhart Jul 21 '15 at 13:10

Assuming two databases are db1 and db2, we can do following:

1) Take backup of db1 & db2 for rollback options:

mysqldump -u<root> -p<pass> --databases db1 db2 > db1_db2.sql

2) Take backup of db1 (only data):

mysqldump -u<root> -p<pass> --no-create-info db1 > db1.sql

3) Load db1's dump to db2:

cat db1.sql | mysql db2 

So if both databases have same tables, it will insert the data into tables. If table doesn't exist then this will generate error. You can skip those errors and let it continue as:

cat db1.sql | mysql -u<user> -p<pass> db2 --force
  • Hey thanks for your answer. But I have only example1.db & example2.db. These two I want to merge. The tables included in both the db's are same. Also which interface should be used to combine this? – user3625602 Jul 30 '15 at 10:06
  • I'm not sure how do you mean by which - interface!! You can follow above steps on terminal. Bad thing here is that if you have autoincrement columns then this will not work and will generate errors. – mysql_user Jul 30 '15 at 11:17
  • Hi, I am using sqlite3 database which has *.db extension. I think there is another way to treat with these files. Please let me know if you have any information about this. – user3625602 Aug 20 '15 at 6:47
  • Above answer should be for MySQL and not sqlite! – mysql_user Aug 20 '15 at 8:56
  • Yes... But do you know how we can do this with sqlite? – user3625602 Sep 9 '15 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.