tags:

views:

201

answers:

2

I do a fair bit of work at the command line. When I start my computer up on of the first things I do is open up a terminal window for mysql, and one for the Rails console and usually a third running mongrel. Setting it up every morning is a bit of a drag so I would like to script it. How can I open a terminal window, log into mysql, select my development database and then leave it there at the mysql prompt waiting for me. I know how to execute a mysql statement from bash, I just don't know how to get it to leave the prompt open for me to work with after. Hopefully that is clear!

Update: Combining the two answers below got things working for mysql. Thanks!

Now I am trying to get a gnome-terminal window to stay open running the Rails script/server command so I can watch the output. For some reason the following closes almost immediately:

gnome-terminal  -e "ruby /home/mike/projects/myapp/script/server" &
+1  A: 

xterm provides an option for executing a command:

xterm -e myCommandToLogIntoMysql &

You can put a sequence of such xterm commands into a shell script.

mouviciel
xterm is so 1987...
axel_c
A: 

How can I open a terminal window, log into mysql, select my development database and then leave it there at the mysql prompt waiting for me.

mysql -u user -ppassword -D database_name

Remember not to put space between "-p" and password. Note - this is a bit insecure, as your password is visible in process list so anyone can read it using ps. You can, however, put your MySQL password in ~/.my.cnf file.

el.pescado