混合使用SQL和shell命令
mysql下可以用批处理模式运行SQL,比如:
shell> mysql -h host -u user -p < batch-file.sql
Enter password: ********
但是平常往往需要在执行sql的同时,运行一些shell脚本进行进一步计算,保存日志之类的。这个可以靠mysql的system命令来实现,例如:
CODE:
-
# Mixing shell commands and SQL queries in batch mode- demo script
-
use test;
-
#INSTALL PLUGIN example SONAME 'ha_example.so'; #Ignore statement
-
system cp /tmp/mysqld.trace logs/init.trace # Shell commands prefixed with a 'system'
-
create table new4(num integer) engine=EXAMPLE;
-
system cp /tmp/mysqld.trace logs/after_create.trace # Shell commands prefixed with a 'system'
-
system diff logs/init.trace logs/after_create.trace # Shell commands prefixed with a 'system'
注意
- system命令只在类unix操作系统上有效。
- 可以在存储过程中使用system。
作者: Volcano 发表于July 1, 2008 at 9:19 am
Linc 于 2008-10-30 @ 22:32:02 留言 :
非常感谢你的这篇文章!
请问,在存储过程中,怎么使用system?
举个例子吧,谢谢!(希望能回复到我的邮箱,麻烦你了。)
maketop 于 2009-06-10 @ 21:45:34 留言 :
在存储过程中使用system有没有什么权限的设置要求?