0

hellow

Dumped x.sql file from db and then trying to find way to insert data from x.sql file to existent tbl in another server. But mysql execute all the concept of the x.sql ( that include "drop table if exists tbl and create new")

mysql --host= --user= --password= schema tbl < x.sql

there is away may be to dump tbl (with out "drop and create new" commands only insert )?

3
  • how and what x.sql contain are quite important. How was it generated? Is it exactly the same table structure? What statements does it contain? Can you edit the file to remove the drop table and create table? Are you likely to have duplicate rows on the primary / unique key?
    – danblack
    Nov 8, 2018 at 7:30
  • Restore it into separate (temporarily created) database, than join data using simple INSERT query.
    – Akina
    Nov 8, 2018 at 7:35
  • @danblack from server x table tbl used mysqldump --where id > x . then to server y import data mysql --host= --user= --password= schema tbl < x.sql . but it drop tbl on server y and create the same tbl
    – Stas Rozen
    Nov 8, 2018 at 8:14

1 Answer 1

1

If you can rebuild the x.sql, run mysqldump with suitable option such as --no-drop-tables, --no-creates (or whatever they are). Then look at the dump file to make sure there are no surprises in it.

If you can't rebuild x.sql, then edit it to get rid of drops/creates/etc.

If there are no USE statements in x.sql, you can say mysql ... new_db < x.sql (after doing CREATE DATABASE new_sql). Then play SQL games to copy the data from new_db.foo to old_db.foo. (Provide more details if you need help in this area.)

Your Answer

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

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