如何在MySQL Workbench 6.2查询中运行.sql文件? [英] How to run a .sql file as part of a MySQL Workbench 6.2 query?

查看:457
本文介绍了如何在MySQL Workbench 6.2查询中运行.sql文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL Workbench 6.2 [Windows7],我想用所有步骤创建一个脚本.在这些步骤中,我从计算机上存储了一系列.sql文件,这些文件创建并填充表. 我想从查询选项卡运行这些文件,但是每次使用此命令时:

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:

源C:/Users/[用户名]/Desktop/sampdb/create_president.sql;

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

我收到错误1064,提示

I get an Error 1064, which says

错误代码:1064.您的计算机中有错误 SQL语法;检查与您的MySQL服务器相对应的手册 在'mysql>源代码附近使用的正确语法的版本 C:/Users/[用户名]/Desktop/sampdb/create_president.sql在第1行"

"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 Workbench脚本中引用.sql文件?

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

我应该在MySQL Workbench中使用什么代码而不是source?我已经尝试过LOAD DATA LOCAL INFILE 'C:/Users/[username]/Desktop/sampdb/create_president.sql';,但是也没有用.知道有什么问题吗?

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?

*仅提供其他信息,create_president.sql包含以下代码:

*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
);

推荐答案

source命令是MySQL Workbench不支持的纯(命令行)客户端特定命令.只需加载sql文件即可运行它.

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)

您的SQL文件包含DDL. LOAD DATA INFILE但是仅导入DML. MySQL命令行客户端的SOURCE命令无法替代.但是,在我们的待办事项列表中,可以找到MySQL Workbench中的支持.

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.

这篇关于如何在MySQL Workbench 6.2查询中运行.sql文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆