1

I have two .sql files and some of lines of these two files are the same, that create same tables and insert same data.
When I try to import, the first one successfully imports but the second one says:

Table 'access' already exists

These two files have more than 70K lines, the first one has 80K and the second has 200K.
I need to import both. Although some lines and some insert queries are the same, in fact the second file has more tables which do not exist in the first one.
How can I solve this issue? I mean to create the table again, and if requires insert the data again.
Thanks in advance.

Saeed
  • 1,118
  • 2
  • 8
  • 19
  • and why dont you delete the create table command from second file ? – Andrew Apr 11 '18 at 15:52
  • @Andrew because there are maybe about 20K lines, and finding one by one which line exists to delete, is not a good idea. – Saeed Apr 11 '18 at 15:55
  • how are the files generated? how about generate them without the create table commands? – Andrew Apr 11 '18 at 16:25
  • 1
    use find and replace, and change all create table commands to create table if not exist – Andrew Apr 11 '18 at 16:25
  • The two sql backups are old and I can't backup them again. Also my primary laptop is being repaired and this laptop (low laptop) is not good enough to install wamp/xampp to import in two separate databases. My hosting does not let me create more that one database. That's so complicated. – Saeed Apr 11 '18 at 16:29
  • Thanks @Andrew, and what about the insert into queries? How to let them overwrite? – Saeed Apr 11 '18 at 16:51
  • https://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql – Andrew Apr 11 '18 at 17:38
  • fantastic, ill post it as an answer if u want to accept boss – Andrew Apr 11 '18 at 18:10

1 Answers1

0

Use find and replace, and change all create table commands to create table if not exist.

https://dev.mysql.com/doc/refman/5.5/en/create-table.html

And then for the data, change to insert ignore into

How to 'insert if not exists' in MySQL?

Andrew
  • 13,934
  • 8
  • 78
  • 93