数据导入是否替换了MySQL Workbench中的现有数据?

时间:2021-05-04 16:25:03

I'm working with a database in a development environment in MySQL Workbench. I have everything ready to go and need to move it to a prod database. I've exported it to a sql file but I'm unsure if I'm approaching the import the correct way.

我正在使用MySQL Workbench中的开发环境中的数据库。我已经准备好了一切,需要将它移动到prod数据库。我已经将它导出到一个sql文件中,但我不确定是否以正确的方式处理导入。

If I use the "Data Import/Restore" feature, select my SQL file, and import, will it replace the existing data in the database (what I want to happen) or will it add new records to each table for the new data?

如果我使用“数据导入/恢复”特性,选择我的SQL文件并导入,它将替换数据库中的现有数据(我希望发生什么),还是为新数据向每个表添加新记录?

The schema is the same in each database. I just need to replace the old data in the prod database with the new data from dev.

每个数据库中的模式都是相同的。我只需要用dev的新数据替换prod数据库中的旧数据。

Thanks for your help

谢谢你的帮助

1 个解决方案

#1


2  

That depends on how your export-file looks. Just open it in a text editor and read over the statements in your export-file.

这取决于您的导出文件的外观。只需在文本编辑器中打开它,并阅读导出文件中的语句。

By default it should contain statements like:

默认情况下,它应该包含如下语句:

CREATE TABLE IF NOT EXISTS `customer` (
  `CUSTOMER_ID` int(11) NOT NULL,
  `CUSTOMER_NM` varchar(100) DEFAULT ''
) EN

and right after it the data of this table:

下面是这个表格的数据

INSERT INTO `customer` (`CUSTOMER_ID`, `CUSTOMER_NM`) VALUES
(0, 'Dummy Customer');
(1, 'Dummy Two');

Since your tables already exist in your PROD-Environment it will not delete, create or replace them (Note the CREATE TABLE IF NOT EXISTS-Statement). The INSERT-Stamement will be executed (there is no condition which says it shouldn't).

由于您的表已经存在于您的prod环境中,因此它不会删除、创建或替换它们(如果不是存在语句,请注意创建表)。插入- stamement将被执行(没有条件说不应该执行)。

So after importing your file you will have your previous PROD-Data in your database + the imported DEV-Data your your DEV-Environment.

因此,在导入文件之后,您将在数据库中拥有以前的prod数据和导入的dev数据。

On the other hand it could contain a statement like:

另一方面,它可以包含如下语句:

DROP TABLE IF EXISTS `customer`

And right after it the CREATE-Statement followed by some INSERT-Statements. In this case your whole PROD-Database will be replaced by the DEV-Database as you want it to.

在它之后是创建语句后面是插入语句。在这种情况下,您的整个prod数据库将被您想要的数据库所替代。

#1


2  

That depends on how your export-file looks. Just open it in a text editor and read over the statements in your export-file.

这取决于您的导出文件的外观。只需在文本编辑器中打开它,并阅读导出文件中的语句。

By default it should contain statements like:

默认情况下,它应该包含如下语句:

CREATE TABLE IF NOT EXISTS `customer` (
  `CUSTOMER_ID` int(11) NOT NULL,
  `CUSTOMER_NM` varchar(100) DEFAULT ''
) EN

and right after it the data of this table:

下面是这个表格的数据

INSERT INTO `customer` (`CUSTOMER_ID`, `CUSTOMER_NM`) VALUES
(0, 'Dummy Customer');
(1, 'Dummy Two');

Since your tables already exist in your PROD-Environment it will not delete, create or replace them (Note the CREATE TABLE IF NOT EXISTS-Statement). The INSERT-Stamement will be executed (there is no condition which says it shouldn't).

由于您的表已经存在于您的prod环境中,因此它不会删除、创建或替换它们(如果不是存在语句,请注意创建表)。插入- stamement将被执行(没有条件说不应该执行)。

So after importing your file you will have your previous PROD-Data in your database + the imported DEV-Data your your DEV-Environment.

因此,在导入文件之后,您将在数据库中拥有以前的prod数据和导入的dev数据。

On the other hand it could contain a statement like:

另一方面,它可以包含如下语句:

DROP TABLE IF EXISTS `customer`

And right after it the CREATE-Statement followed by some INSERT-Statements. In this case your whole PROD-Database will be replaced by the DEV-Database as you want it to.

在它之后是创建语句后面是插入语句。在这种情况下,您的整个prod数据库将被您想要的数据库所替代。