Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip already created tables while importing mysql dump by command line

Tags:

database

mysql

Is there any way to skip already created tables while importing ? I am trying to import 2GB of database using command prompt but the operation is aborted by mistake. Now if i will do the import again it will drop each table and create it again, That will take very long time.

I want to skip those tables from import which is already created or can i start it from where it was aborted ? I am using this command

mysql -u root -p my_database_name < db_dump.sql
like image 508
Abhijeet Sharma Avatar asked Jun 10 '14 11:06

Abhijeet Sharma


People also ask

Does Mysqldump drop table?

mysqldump can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it. Buffering in memory can be a problem if you are dumping large tables. To dump tables row by row, use the --quick option (or --opt , which enables --quick ).

How do I drop a MySQL database from the command line?

First, launch the MySQL workbench and log in to the MySQL Server. Second, right-click the database that you want to remove, for example, testdb2 and choose the Drop Schema... option. Third, MySQL Workbench displays a dialog to confirm the deletion.


1 Answers

Run your dump through a filter which replaces each 'CREATE TABLE' with 'CREATE TABLE IF NOT EXISTS', like in

cat db_dump_sql | sed "s/CREATE TABLE /CREATE TABLE IF NOT EXISTS /g" | mysql -uroot -p my_database_name

Or edit db_dump.sql and search/replace interactively.

like image 154
Alex Monthy Avatar answered Sep 20 '22 21:09

Alex Monthy