Thursday, 14 August 2014

HowTo : Execute BASH Shell Commands over MySQL environment in Linux?

Yes, We can execute shell commands over mysql environment without exit by adding "\! " before commands as like "\! command",

mysql> \! uptime
 06:52:18 up 36 min,  1 user,  load average: 0.00, 0.00, 0.00
mysql>

mysql> \! pwd
/root
mysql>

(or) We can get the shell prompt here by doing,

mysql> \! bash

(or)

mysql> \! sh


HowTo: Get current working database information in mysql?

Add the below lines in /etc/my.cnf

[mysql]
prompt=`mysql(\d)>`

your  mysql environment will be,


`mysql((none))>`


To revert this,

HowTo: Get hostname in mysql environment?

Add the below lines in /etc/my.cnf

[mysql]
prompt=`mysql(\h)>`

Also in /root/.my.cnf should have below,
[client]
host=valid.hostname.com
user="root"
pass="password"

please make sure the hostname should be valid and added in /etc/hosts


If you would like to return default PROMPT of mysql(this time only)

`mysql(ranjith.time.com)>`\R
Returning to default PROMPT of mysql>
mysql>

Enjoy !!....

No comments:

Post a Comment