mysql中overwrite,如何從命令行WITH overwrite導入MySQL轉儲

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

我google了很多,我找不到任何關於它!

[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 ?

與mysql -f是一樣的。我希望簡單地導入.sql並重寫那些表,有人可以幫助我嗎?

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

附:我知道當你導出數據庫時你可以選擇“DROP TABLE”選項,但如果我有備份,沒有這個聲明?我怎么強迫?謝謝

3 个解决方案

#1

4

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.

您是否試圖覆蓋整個數據庫?如果是這樣,您可以手動刪除所有表,然后運行導入腳本。這在phpmyadmin中很容易做到。如果您正在使用CLI,最快的方法是使用DROP DATABASE databasename然后創建數據庫,但我認為您必須為任何非root用戶重新授予權限。

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.

另一種選擇是打開轉儲文件並在每個CREATE TABLE命令之前添加DROP TABLE tablename。你可以用一些聰明的正則表達式輕松地做到這一點。

#2

21

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

當你做mysqldump時添加--add-drop-table(就像提到的twihoX)。然后像往常一樣進行導入。所以類似於:

mysqldump --add-drop-table -u user -p > dumpfile.sql

mysql -u user -p < dumpfile.sql

#3

0

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

我建議--add-drop-table選項。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值