Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute shell command from within a MySQL client?

Tags:

shell

mysql

In oracle database, command "host" can be used to run bash command from database command window. Is there a equivalent command as "host" in mySql?

like image 463
Progress Programmer Avatar asked May 30 '09 08:05

Progress Programmer


People also ask

How do I run a shell code in MySQL?

The \edit ( \e ) command opens a command in the default system editor for editing, then presents the edited command in MySQL Shell for execution. The command can also be invoked using the key combination Ctrl-X Ctrl-E. For details, see Section 5.4, “Editing Code”.

Is MySQL shell and MySQL command line client same?

The MySQL Shell is a big advancement over the old command line client. First, it has three dialects — SQL, Python, and JavaScript. If you have libraries or code in either Python or JavaScript to use on your data then you can use them.


2 Answers

You can use the system command.

system command, \! command

Executes the given command using your default command interpreter.

The system command works only in Unix.

Example:

system ls -l
like image 146
Ayman Hourieh Avatar answered Oct 09 '22 02:10

Ayman Hourieh


As an additional tweak, on most "'nix" systems you can actually do something like this:

mysql> system bash

And have the entire terminal at your disposal. This is particularly effective if you're doing code work in the terminal that interfaces with MySQL; from the shell, typing "exit" will take you back into the MySQL monitor/client, so you can go back and forth quite easily.

Obviously, other shells ("mysql> system tcsh") would work as well.

like image 40
Kevin_Kinsey Avatar answered Oct 09 '22 03:10

Kevin_Kinsey