如何从命令行WITH overwrite导入MySQL转储 [英] How to import a MySQL dump from command line WITH overwrite

查看:172
本文介绍了如何从命令行WITH overwrite导入MySQL转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我google了很多,我找不到任何关于它!

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

mysql -f 是一样的。我希望简单地导入.sql并重写那些表,有人可以帮助我吗?

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

p.s。我知道当你导出数据库时你可以选择DROP TABLE选项,但如果我有备份,没有这个声明?我怎么强迫?谢谢

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

推荐答案

您是否试图覆盖整个数据库?如果是这样,您可以手动删除所有表,然后运行导入脚本。这在phpmyadmin中很容易做到。如果您正在使用CLI,最快的方法是使用 DROP DATABASE databasename 然后 create database ,尽管如此我想你必须为任何非root用户重新授予权限。

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.

另一种选择是在每个CREATE TABLE命令之前打开转储文件并添加 DROP TABLE tablename 。你可以用一些聪明的正则表达式轻松地做到这一点。

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.

这篇关于如何从命令行WITH overwrite导入MySQL转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆