How to import a MySQL dump from command line WITH overwrite

这一生的挚爱 提交于 2019-12-05 01:25:22

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.

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 > dumpfile.sql

mysql -u user -p < dumpfile.sql 

I'd suggest --add-drop-table option.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!