Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a MySQL dump from command line WITH overwrite

Tags:

i googled a lot and i can't found nothing about it !

[root@someday backups]# mysql -u username_1 -p db_1 < tables_to_import/tables.sql  ERROR 1050 (42S01) at line 19: Table 'ps_customer' already exists 

with mysql -f is the same. i wish simply import that .sql and rewrite that tables, can someone help me ?

p.s. i know that when you export a db you can choose option "DROP TABLE" but if i have a backup, without this declaration ? how can i force ? Thanks

like image 372
CalfCrusher Avatar asked Oct 01 '12 16:10

CalfCrusher


People also ask

How do I overwrite an existing MySQL database?

What you can do is log in to MySQL and drop the tables that you plan to overwrite, then use --force on import.

How do I import a dump file in MySQL?

From the normal command line, you can import the dump file with the following command: mysql -u username -p new_database < data-dump. sql.

How do I dump a MySQL database in terminal?

To dump entire databases, do not name any tables following db_name , or use the --databases or --all-databases option. To see a list of the options your version of mysqldump supports, issue the command mysqldump --help .


1 Answers

When you do mysqldump add --add-drop-table (like twihoX mentioned). Then do your import as usual. So something like:

mysqldump --add-drop-table -u user -p db_1 > dumpfile.sql  mysql -u user -p db_1 < dumpfile.sql  
like image 153
DrewB Avatar answered Oct 21 '22 07:10

DrewB