I'd like to use . to call sql script from inside a stored proc like so...
我想用。从存储过程中调用sql脚本就像这样......
delimiter ///
create procedure append_procedure()
BEGIN
\. test.sql;
END; ///
delimiter ;
I'm getting a "failed to open 'test.sql;' " error when I run it this way. I've also tried ! but then I get a permission denied error. However, I can't eliminate the ; or the whole thing is broken. Is there a way around this?
我得到了一个“未能打开'test.sql;' “当我以这种方式运行时出错。我也试过了!但后来我得到了一个允许拒绝错误。但是,我无法消除;或者整件事都破了。有没有解决的办法?
What am I doing wrong?
我究竟做错了什么?
2 个解决方案
#1
5
There is a set of commands that are builtin to the mysql client. They're documented under "mysql
Commands." These include DELIMITER, SOURCE, HELP, CONNECT, USE, QUIT, etc.
有一组内置于mysql客户端的命令。它们记录在“mysql命令”下。这些包括DELIMITER,SOURCE,HELP,CONNECT,USE,QUIT等。
The \.
(or SOURCE
) command is one of these builtins. You can't execute these builtin commands programmatically, nor from within a stored procedure.
\ \。 (或SOURCE)命令是其中一个内置命令。您不能以编程方式执行这些内置命令,也不能在存储过程中执行这些内置命令。
It'd be like trying to run a UNIX shell builtin from a C program using execl()
.
这就像尝试使用execl()从C程序运行内置的UNIX shell。
A different analogy might be in a web browser, where you can type in special requests like "about:
" that are handled by the browser app itself; these don't result in any HTTP request to a remote web site.
一个不同的类比可能是在Web浏览器中,您可以在其中键入由浏览器应用程序本身处理的特殊请求,如“about:”;这些不会导致对远程网站的任何HTTP请求。
Also, it wouldn't help if you could source a script from within a stored procedure, because the script itself likely contains a bunch of commands that are mysql client builtins, and thus cannot be run by the stored proc.
此外,如果您可以从存储过程中获取脚本,那将无济于事,因为脚本本身可能包含一堆mysql客户端内置的命令,因此无法由存储过程运行。
See also my answers to these related questions:
另见我对这些相关问题的回答:
- Running MySQL *.sql files in PHP
- Loading .sql files from within PHP
- PHP: multiple SQL queries in one mysql_query statement
在PHP中运行MySQL * .sql文件
从PHP中加载.sql文件
PHP:一个mysql_query语句中的多个SQL查询
#2
0
If you're on Sql Sevrer 2005 you can use the xp_cmdshell command.
如果您使用的是Sql Sevrer 2005,则可以使用xp_cmdshell命令。
http://msdn.microsoft.com/en-us/library/ms175046(SQL.90).aspx
Or
http://www.sqlservercentral.com/articles/Administering/scriptscheduling/450/
#1
5
There is a set of commands that are builtin to the mysql client. They're documented under "mysql
Commands." These include DELIMITER, SOURCE, HELP, CONNECT, USE, QUIT, etc.
有一组内置于mysql客户端的命令。它们记录在“mysql命令”下。这些包括DELIMITER,SOURCE,HELP,CONNECT,USE,QUIT等。
The \.
(or SOURCE
) command is one of these builtins. You can't execute these builtin commands programmatically, nor from within a stored procedure.
\ \。 (或SOURCE)命令是其中一个内置命令。您不能以编程方式执行这些内置命令,也不能在存储过程中执行这些内置命令。
It'd be like trying to run a UNIX shell builtin from a C program using execl()
.
这就像尝试使用execl()从C程序运行内置的UNIX shell。
A different analogy might be in a web browser, where you can type in special requests like "about:
" that are handled by the browser app itself; these don't result in any HTTP request to a remote web site.
一个不同的类比可能是在Web浏览器中,您可以在其中键入由浏览器应用程序本身处理的特殊请求,如“about:”;这些不会导致对远程网站的任何HTTP请求。
Also, it wouldn't help if you could source a script from within a stored procedure, because the script itself likely contains a bunch of commands that are mysql client builtins, and thus cannot be run by the stored proc.
此外,如果您可以从存储过程中获取脚本,那将无济于事,因为脚本本身可能包含一堆mysql客户端内置的命令,因此无法由存储过程运行。
See also my answers to these related questions:
另见我对这些相关问题的回答:
- Running MySQL *.sql files in PHP
- Loading .sql files from within PHP
- PHP: multiple SQL queries in one mysql_query statement
在PHP中运行MySQL * .sql文件
从PHP中加载.sql文件
PHP:一个mysql_query语句中的多个SQL查询
#2
0
If you're on Sql Sevrer 2005 you can use the xp_cmdshell command.
如果您使用的是Sql Sevrer 2005,则可以使用xp_cmdshell命令。
http://msdn.microsoft.com/en-us/library/ms175046(SQL.90).aspx
Or
http://www.sqlservercentral.com/articles/Administering/scriptscheduling/450/