skip to Main Content

I need to dump data from one table in my MySQL 8 database and reimport into a different table which already exists and has it’s schema. The schema is identical between the two such as columns, how can I achieve this, i just need the row imsert statements from mysqldump without locking and create info

My export:

mysqldump -u root -p --no-create-info icicle_db users > users_existing.sql

I’ve tried to import

mysqldump -u root -p --no-create-info icicle_db users_new < users_existing.sql

But users_existing.sql contains references to the old table, i just need insert data not other schema. I’m trying it on a small table before trying a table with millions of rows. What am i missing?

2

Answers


  1. This seems to have been asked here:

    How can I import a mysql dump?

    Quick answer:

    mysql -uroot -p database_name < backup.sql
    
    
    Login or Signup to reply.
  2. But users_existing.sql contains references to the old table, i just
    need insert data not other schema. I’m trying it on a small table
    before trying a table with millions of rows. What am I missing?

    You need to replace the table name in users_existing.sql file.

    This can be done using sed command.

    sudo sed -i 's/INSERT INTO `users`/INSERT INTO `users_new`/g' users_existing.sql
    

    Then proceed with the restore

    mysql -u root -p icicle_db < users_existing.sql
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search