MySQL mysql系统命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7457056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql system command
提问by Alex
I am in MySQL and would like to change the current working directory. I tried to execute:
我在 MySQL 中,想更改当前工作目录。我试图执行:
mysql> system cd './my_dir'
However, this does not seem to work. Has anyone run into a similar problem?
但是,这似乎不起作用。有没有人遇到过类似的问题?
回答by Paul
System is going to spawn a child process to run a shell command.....
系统将产生一个子进程来运行一个 shell 命令......
Current working directory is a process level property....so you can't change it in the parent from a child process. That's why it doesn't work.
当前工作目录是一个进程级别的属性......所以你不能在子进程的父进程中更改它。这就是它不起作用的原因。
I briefly scanned the MySQL docs at http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.htmlbut didn't see a direct CD command that changes the working directory. I think an adventurous person could write one....
我在http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html 上简要扫描了 MySQL 文档,但没有看到更改工作目录的直接 CD 命令。我认为一个喜欢冒险的人可以写一个......
回答by jbrahy
If you want to change your current working directory for a script, then use the && between the CD and script so it will change directory and then if that's successful it will execute the second command.
如果要更改脚本的当前工作目录,请在 CD 和脚本之间使用 && 以便更改目录,然后如果成功,它将执行第二个命令。
mysql> SYSTEM cd /home && ls
回答by MrSampson
What you're looking for is the escape to shell command: \!
您正在寻找的是转义 shell 命令: \!
mysql>\! cd ./my_dir
You can even use it to escape to the shell completely and then come back to the mysql environment.
您甚至可以使用它完全转义到shell,然后返回到mysql环境。
mysql>\! bash
bash>cd ./my_dir
bash>exit
mysql>SELECT * ALL FROM <table>;