How to import a MySQL dump from command line WITH overwrite
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
Are you trying to overwrite the entirety of the database? If so, you could manually drop all the tables, and then run your import script. This is easy to do in phpmyadmin. If you're using the CLI, the fastest way would be to use DROP DATABASE databasename
and then create database
, though I think you'd then have to re-grant privileges for any non-root users.
Another option would be to open up your dump file and add DROP TABLE tablename
before each of the CREATE TABLE commands. You could probably do this easily with some clever regex.