如何从 Mysql 工作台中运行脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29546081/
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
How to run script from within Mysql workbench?
提问by draca
I have a SQL script to distribute to others to run from a MySQL IDE, not from a MySQL command prompt.
我有一个 SQL 脚本可以分发给其他人,以便从 MySQL IDE 运行,而不是从 MySQL 命令提示符运行。
I want the user to load the script into a window of workbench (or another IDE like sqlyog) and just run the script, which inserts records based on variables, for example:
我希望用户将脚本加载到工作台(或其他 IDE,如 sqlyog)的窗口中,然后运行脚本,该脚本根据变量插入记录,例如:
SELECT value FROM mytable WHERE key = "mykey" into @columnid;
INSERT INTO mytable (col2,col3) VALUES (
@columnid,
'testvalue'
)
We all have MySQL Workbench installed but I don't see a way to do this from workbench.
我们都安装了 MySQL Workbench,但我看不到从工作台执行此操作的方法。
Is there a way to run a script (that is in an editor window) from workbench (or any other MySQL IDE) the way you can run scripts from other database IDE's like Toad or SQL Server Management Studo?
有没有办法从工作台(或任何其他 MySQL IDE)运行脚本(在编辑器窗口中),就像从其他数据库 IDE(如 Toad 或 SQL Server Management Studo)运行脚本一样?
回答by Philip Olson
There are two differentmethods:
有两种不同的方法:
File -> Open SQL Script: This simply loads the file contents into a new SQL query tab in the SQL editor. From here, execute the query exactly like you would if you typed it in.
File -> Run SQL Script: This opens the SQL script in its own "Run SQL Script" wizard that includes a [Run] button to execute the query. This only displays part of the query, but does allow the user to override the selected schema and character set. Note:This feature was added in Workbench 6.2.
文件 -> 打开 SQL 脚本:这只是将文件内容加载到 SQL 编辑器中的新 SQL 查询选项卡中。从这里开始,完全按照您输入的方式执行查询。
文件 -> 运行 SQL 脚本:这将在其自己的“运行 SQL 脚本”向导中打开 SQL 脚本,该向导包括一个 [运行] 按钮来执行查询。这仅显示查询的一部分,但允许用户覆盖选定的模式和字符集。注意:此功能是在 Workbench 6.2 中添加的。
I suspect you want the simpler "Run SQL Script".
我怀疑您想要更简单的“运行 SQL 脚本”。
回答by chamzz.dot
After open the Mysql workbench ,Just follow these steps,
打开Mysql工作台后,只需按照以下步骤操作,
- start the server
- 启动服务器
server -> server status -> start server
服务器 -> 服务器状态 -> 启动服务器
- create the relevant database
- 创建相关数据库
navigator(in left side) -> schemas -> (right click) new schema -> your new db name ->ok
导航器(在左侧)-> 模式->(右键单击)新模式-> 您的新数据库名称-> 确定
- set the new db as default schema
- 将新数据库设置为默认架构
right click the new db name -> set as default schema
右键单击新的数据库名称-> 设置为默认架构
- Run the query
- 运行查询
file-> open a sql script -> Open relevant script -> execute it
文件->打开一个sql脚本->打开相关脚本->执行它
- Finish
- 结束
回答by Rahul Tripathi
You just need to go to the File
option and then click Open SQL Script
.
您只需转到该File
选项,然后单击Open SQL Script
。
You can refer: SQL Query Window Toolbarand a small video
可以参考:SQL Query Window Toolbar和一个小视频
回答by O. Jones
Most RDMS IDE tools have a way to open a SQL script from a menu item.
大多数 RDMS IDE 工具都有从菜单项打开 SQL 脚本的方法。
In Workbench, it's File > Open SQL Script... like Maximus2012 wrote.
在 Workbench 中,它是 File > Open SQL Script... 就像 Maximus2012 写的那样。
In HeidiSQL, it's File > Load SQL File ...
在 HeidiSQL 中,它是文件 > 加载 SQL 文件...