简体   繁体   English

在MySQL Workbench中将数据从一个模式导出到另一个模式

[英]Exporting data from one schema to another in MySQL Workbench

Is there a way to export the tables and data from one schema to another? 有没有办法将表和数据从一个模式导出到另一个模式? The manage import/export option asks me to select a server to connect to, which comes up blank. 管理导入/导出选项要求我选择要连接的服务器,该服务器显示为空白。 I'm currently connected to a server that my school has rented, specifically for this class, so I don't have any admin rights. 我目前已连接到我学校租用的服务器,专门用于此类,因此我没有任何管理员权限。

You can create a dump via Data Export in MySQL Workbench and import that right after the export to a new schema. 您可以通过MySQL Workbench中的Data Export创建转储,并在导出到新架构后立即导入。 MySQL Workbench allows to override the target schema in a dump. MySQL Workbench允许覆盖转储中的目标模式。

If you run into troubles importing your data into the new schema, like not getting any data in it, a workaround might be needed. 如果您在将数据导入新架构时遇到麻烦,例如没有获取任何数据,则可能需要一种解决方法。 I ran an export of a schema from MySQL workbench to a .sql file to later import it in a different schema and the problem was that the .sql file exported maintained the previous schema. 我运行了从MySQL工作台到.sql文件的模式导出,以便稍后在不同的模式中导入它,问题是导出的.sql文件维护了以前的模式。

So if you find this at the beginning of the .sql exported file: 因此,如果您在.sql导出文件的开头找到它:

CREATE DATABASE  IF NOT EXISTS `old_schema` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `old_schema`;

Replace it with this: 替换为:

CREATE DATABASE  IF NOT EXISTS `new_schema` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `new_schema`;

That will do the trick. 那就行了。 In some situations, your .sql file might be of a few hundreds MB so you will have to wait a little until it opens up in your editor. 在某些情况下,您的.sql文件可能只有几百MB,因此您必须等待一段时间才能在编辑器中打开它。 This code should be at the beginning of the file though so it is easy to find. 此代码应位于文件的开头,因此很容易找到。

I hope it helps! 我希望它有所帮助!

in 6.0 and up, it looks like the dump writes out individual tables in a directory that you name the dump. 在6.0及更高版本中,转储看起来像是在您命名转储的目录中写出单个表。 All of the schema and table names are defaulted to your schema that you exported from (as you've noted.) In order to facilitate an import to a new schema, simply run the following in your dump directory: 所有模式和表名都默认为您导出的模式(如您所述)。为了便于导入到新模式,只需在转储目录中运行以下命令:

find . -type f -exec sed -i 's/your_export_schema/your_different_schema_name/g' {} \;

Be careful though, you'll bone your self if you have data in your export that has your old schema name in it. 但是要小心,如果您的导出中包含旧模式名称的数据,那么您将自行处理。

我注意到问题是关于Workbanch,但请注意,phpMyAdmin在数据库操作中直接具有此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM