30

在某些情况下,我不得不执行 mysqldump 来生成 .sql 文件。在对 MySQL 数据库进行一些更改以进行测试和开发后,我想将其恢复到以前的状态。所以我导入了 .sql 文件。过去我删除了数据库并重新创建了它,然后进行了导入。那有必要吗?从 .sql 文件导入会覆盖并完全重新创建数据库及其表,还是附加到它?谢谢!

4

2 回答 2

23

追加到它,除非导入文件专门以不同方式处理表。

于 2012-09-27T11:03:19.153 回答
20

这取决于 SQL 文件包含哪些命令。感兴趣的命令是:

DROP DATABASE xxx;            # will delete the whole database
DROP TABLE xxx;               # unconditionally deletes a table
CREATE TABLE [IF NOT EXISTS]  # if IF NOT EXISTS adds the table, does nothing if exists
                              # otherwise, it adds the table, gives an error if it exists
于 2012-09-27T11:05:49.647 回答