mysql system command

三世轮回 提交于 2019-12-10 11:19:38

问题


I am in MySQL and would like to change the current working directory. I tried to execute:

mysql> system cd './my_dir'

However, this does not seem to work. Has anyone run into a similar problem?


回答1:


System is going to spawn a child process to run a shell command.....

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.html but didn't see a direct CD command that changes the working directory. I think an adventurous person could write one....




回答2:


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.

mysql> SYSTEM cd /home && ls



回答3:


What you're looking for is the escape to shell command: \!

mysql>\! cd ./my_dir

You can even use it to escape to the shell completely and then come back to the mysql environment.

mysql>\! bash
bash>cd ./my_dir
bash>exit
mysql>SELECT * ALL FROM <table>;


来源:https://stackoverflow.com/questions/7457056/mysql-system-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!