将数据和架构导入 MySQL Workbench

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26260235/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:06:05  来源:igfitidea点击:

Importing Data and Schema to MySQL Workbench

mysqlsqlmysql-workbench

提问by FranGoitia

I'm trying to learn SQL and I downloaded a database to practice. I downloaded two files of extension .sql, one is the schema and the other one the actual data. I've also installed MySQL Workbench. I've been googling and I've been trying things to solve this but I don't understand Workbench and I can't load the database.

我正在尝试学习 SQL,我下载了一个数据库来练习。我下载了两个扩展名为 .sql 的文件,一个是架构,另一个是实际数据。我还安装了 MySQL Workbench。我一直在谷歌搜索,我一直在尝试解决这个问题,但我不理解 Workbench,我无法加载数据库。

Where do I import the schema and the data in order to try queries ?

我在哪里导入架构和数据以尝试查询?

Any help would be really appreciated.

任何帮助将非常感激。

回答by Philip Olson

This is simple in Workbench, and I'll use the freely available sakila database as an example. Feel free to apply this to your situation:

这在 Workbench 中很简单,我将使用免费提供的 sakila 数据库作为示例。随意将其应用于您的情况:

  1. Download "sakila" from here: http://dev.mysql.com/doc/index-other.html
  2. Extract it somewhere, in my case, onto the Desktop into a new sakila-db/ directory
  3. Open Workbench
  4. In the Schema Navigator, right-click an empty area and choose "Create Schema"
  5. In the schema creation wizard, name it "sakila", keep the defaults, hit "Apply", finish wizard
  6. Go to "File" -> "Run SQL Script..."
  7. Choose "sakila-schema.sql", make sure "Default Schema Name" is blank or select "sakila", execute
  8. Go to "File" -> "Run SQL Script..."
  9. Choose "sakila-data.sql", execute
  10. Click the "refresh" icon in the Workbench Schema Navigator (or restart Workbench)
  11. Now, use the populated sakila database :)
  1. 从这里下载“sakila”:http: //dev.mysql.com/doc/index-other.html
  2. 在我的情况下,将其解压缩到桌面上的某个新 sakila-db/ 目录中
  3. 开放式工作台
  4. 在架构导航器中,右键单击空白区域并选择“创建架构”
  5. 在模式创建向导中,将其命名为“sakila”,保留默认值,点击“Apply”,完成向导
  6. 转到“文件”->“运行 SQL 脚本...”
  7. 选择“sakila-schema.sql”,确保“Default Schema Name”为空或选择“sakila”,执行
  8. 转到“文件”->“运行 SQL 脚本...”
  9. 选择“sakila-data.sql”,执行
  10. 单击 Workbench Schema Navigator 中的“刷新”图标(或重新启动 Workbench)
  11. 现在,使用填充的 sakila 数据库 :)

Steps (4) and (5) are optional in this case (as executing sakila-schema.sql creates the schema), but the idea is worth mentioning.

在这种情况下,步骤 (4) 和 (5) 是可选的(因为执行 sakila-schema.sql 创建模式),但这个想法值得一提。

Here's how it would look when loading th script into the SQL IDE:

以下是将脚本加载到 SQL IDE 时的外观:

enter image description here

在此处输入图片说明

回答by dr_

The accepted answer is from 4 years ago, so I thought I'd give an update as in MySQL Workbench 6.3 the procedure is a bit different.

接受的答案是 4 年前的,所以我想我会提供更新,因为在 MySQL Workbench 6.3 中,过程有点不同。

You have to select the menu item Server -> Data Import -> Import from Self-Contained Fileand select the SQL file containing the database you want to import.

您必须选择菜单项服务器 -> 数据导入 -> 从自包含文件导入,然后选择包含要导入的数据库的 SQL 文件。

In Default Target Schema, select the database you want to import the SQL dump to, or create a new empty database via New...

Default Target Schema 中,选择要将 SQL 转储导入到的数据库,或通过New...创建一个新的空数据库

Then click on Start Import.

然后单击开始导入

回答by Kumar Kailash

You could use mysql console from terminal. Login through the user id and pass. Then create a Database from the following command is the .sql file does not have one such command to create so.

您可以从终端使用 mysql 控制台。通过用户ID登录并通过。然后从下面的命令创建一个数据库是 .sql 文件没有一个这样的命令来创建。

Create database db-name
use db-name;
SOURCE xyz.sql;

Source command would load the the content from xyz.sql to your database created. This would be reflected later in workbench indeed.

Source 命令会将 xyz.sql 中的内容加载到您创建的数据库中。这确实会在稍后的工作台中反映出来。

回答by alpha9eek

Its very easy on Linux platform just follow below mentioned steps, After downloading zip file of sakila-db, extract it. Now you will have two files, one is sakila-schema.sqland other one is sakila-data.sql.

在 Linux 平台上非常简单,只需按照下面提到的步骤,下载 sakila-db 的 zip 文件后,将其解压缩。现在您将有两个文件,一个是sakila-schema.sql,另一个是sakila-data.sql



  1. Open terminal
  2. Enter command mysql -u root -p < sakila-schema.sql
  3. Enter command mysql -u root -p < sakila-data.sql
  4. Now enter command mysql -u root -pand enter your password, now you have entered into mysql system with defaultdatabase.
  5. To use sakila database, use this command use sakila;
  6. To see tables in sakila-db, use show tablescommand
  1. 打开终端
  2. 输入命令mysql -u root -p < sakila-schema.sql
  3. 输入命令mysql -u root -p < sakila-data.sql
  4. 现在输入命令mysql -u root -p并输入您的密码,现在您已经使用默认数据库进入了 mysql 系统。
  5. 要使用 sakila 数据库,请使用此命令use sakila;
  6. 要查看 sakila-db 中的,请使用 show tables命令


Please take care that extracted files are present in home directoryelse provide the absolute path of these files in all above commands.

请注意提取的文件存在于主目录中,否则在上述所有命令中提供这些文件的绝对路径。