在 MySQL Workbench 中将数据从一种模式导出到另一种模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19944289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exporting data from one schema to another in MySQL Workbench
提问by Hokerie
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.
有没有办法将表和数据从一种模式导出到另一种模式?管理导入/导出选项要求我选择要连接的服务器,该选项为空白。我目前连接到我学校租用的服务器,专门为这个班级,所以我没有任何管理员权限。
回答by Mike Lischke
You can create a dump via Data Export in MySQL Workbench and import that right after the export to a new schema. MySQL Workbench allows to override the target schema in a dump.
您可以通过 MySQL Workbench 中的数据导出创建转储,并在导出后立即导入新模式。MySQL Workbench 允许覆盖转储中的目标模式。
回答by evaldeslacasa
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. This code should be at the beginning of the file though so it is easy to find.
这样就行了。在某些情况下,您的 .sql 文件可能有几百 MB,因此您必须稍等片刻,直到它在您的编辑器中打开。这段代码应该在文件的开头,所以很容易找到。
I hope it helps!
我希望它有帮助!
回答by eggmatters
in 6.0 and up, it looks like the dump writes out individual tables in a directory that you name the dump. 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:
在 6.0 及更高版本中,转储看起来像在您命名转储的目录中写出单个表。所有架构和表名称都默认为您从中导出的架构(正如您所指出的)。为了便于导入新架构,只需在转储目录中运行以下命令:
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.
不过要小心,如果导出中的数据包含旧的架构名称,那么您会自己受苦。
回答by amichai
I noticed that the question was about the Workbanch, but be aware that the phpMyAdmin have this ability directly, in the database operations.
我注意到问题是关于 Workbanch,但请注意 phpMyAdmin 在数据库操作中直接具有此功能。