Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a .sql file as part of a MySQL Workbench 6.2 query?

I'm using MySQL Workbench 6.2 [Windows7] and I want to create a script with all my steps. Among the steps, I have a series of .sql files stored from on my computer that create and populate tables. I want to run these files from the query tab but every time I use this command:

source C:/Users/[username]/Desktop/sampdb/create_president.sql;

I get an Error 1064, which says

"Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql> source C:/Users/[username]/Desktop/sampdb/create_president.sql at line 1 "

MySQL nested script nightmare

Can anyone tell me what I'm doing wrong? How can I refer to a .sql file within a MySQL Workbench script?

What code should I use in the MySQL Workbench instead of source? I have tried LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql'; but it didn't work either. Any idea what can be wrong?

*Just for additional information, create_president.sql contains the following code:

DROP TABLE IF EXISTS president;
#@ _CREATE_TABLE_
CREATE TABLE president
(
  last_name  VARCHAR(15) NOT NULL,
  first_name VARCHAR(15) NOT NULL,
  suffix     VARCHAR(5) NULL,
  city       VARCHAR(20) NOT NULL,
  state      VARCHAR(2) NOT NULL,
  birth      DATE NOT NULL,
  death      DATE NULL
);
like image 382
user3507584 Avatar asked Oct 27 '25 04:10

user3507584


1 Answers

The source command is a pure (command line) client specific command which MySQL Workbench does not support. Just load the sql file to run it.

Update (after you edited your question)

Your SQL file contains DDL. LOAD DATA INFILE however only imports DML. There's no replacement for the MySQL commandline client's SOURCE command. Support for that in MySQL Workbench is however on our todo list.

like image 110
Mike Lischke Avatar answered Oct 29 '25 19:10

Mike Lischke