18

I have a SQL script to distribute to others to run from a MySQL IDE, not from a MySQL command prompt.

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:

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.

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?

2
  • 1
    File > Open SQL Script ? Commented Apr 9, 2015 at 18:23
  • You'll need to specify a default database if you aren't using a database prefix. (Right click on Database, set as default, or something of the likes) Commented Apr 9, 2015 at 18:25

4 Answers 4

26

There are two different methods:

  1. 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.

  2. 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.

I suspect you want the simpler "Run SQL Script".

Sign up to request clarification or add additional context in comments.

1 Comment

For very long scripts (e.g. restoring from backup) I think the Run SQL Script option is preferable as it doesn't load the entire script.
4

You just need to go to the File option and then click Open SQL Script.

You can refer: SQL Query Window Toolbar and a small video

Comments

3

After open the Mysql workbench ,Just follow these steps,

  1. start the server

server -> server status -> start server

  1. create the relevant database

navigator(in left side) -> schemas -> (right click) new schema -> your new db name ->ok

  1. set the new db as default schema

right click the new db name -> set as default schema

  1. Run the query

file-> open a sql script -> Open relevant script -> execute it

  1. Finish

Comments

1

Most RDMS IDE tools have a way to open a SQL script from a menu item.

In Workbench, it's File > Open SQL Script... like Maximus2012 wrote.

In HeidiSQL, it's File > Load SQL File ...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.