聘我网

新概念招聘3.0

如何从MySQL中运行shell命令?

vote up0vote downstar
MySQL > ...

我想在上面这样的MySQL命令行执行shell命令,该如何实现呢?

 

2 个答复

vote up0vote downcheck

如果在linux环境的话可以用\!来执行shell命令:

mysql> \! ping localhost;
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.000 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.000 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.000 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.000 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.000 ms

--- localhost ping statistics ---
链接
vote up0vote down

反过来也是可以的,即从shell中运行mysql语句:

[teng.jia@dev-test pjbaby]$ mysql test -uroot -p111111 -e 'select id from project' 
+----+
|   id  |
+----+
|  7    |
|  8    |
|  9    |
| 11   |
| 12   |
| 18   |
+----+
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.