是否将.sql文件导入MySQL会覆盖现有数据库还是附加到它?

时间:2022-04-05 02:44:32

In some cases, I've had to do a mysqldump to produce a .sql file. After making some changes to the MySQL database for testing and development I want to restore it to the way it was before. So I import the .sql file. In the past I have delete the db and re-created it, and then did te import. Is that necessary? Does import from a .sql file overwrite and totally re-create the database and it's tables, or does it append to it? Thanks!

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

2 个解决方案

#1


15  

It depends on what commands the SQL file contains. Commands of interest are:

它取决于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

#2


18  

Appends to it, unless the import file specifically treats tables differently.

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

#1


15  

It depends on what commands the SQL file contains. Commands of interest are:

它取决于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

#2


18  

Appends to it, unless the import file specifically treats tables differently.

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