For those of you that haven’t committed the database username and passwords for your many apps to memory yet, there comes some help from edge Rails – the addition of a dbconsole script that will automatically drop you into a database prompt using the info in config/database.yml configuration.
In an edge rails app that has a mysql db config:
Update: Because of the insecure nature of passing in the password on the command line on shared hosts – you now need to use the -p or --include-password option to force the password to be read from your config file.
script/dbconsole -p
...
mysql>
And there I am, logged into the dev database in the mysql command prompt. No scrounging around for that app-specific username or db name or cat ing the config/database.yml file anymore.
tags: ruby, rubyonrails

Yay!
No more…
cat config/database.ymlto grab the username and password. :-)This leaves the MySQL password in the output of ps. The same is true in the case of the environment variable used for postgres.
Yep, and my db_console plugin (from whence this script came) provides this functionality for non-Edge Rails users.
Jordi—if you know of an alternative technique for giving the password to mysql, then let me know. The environment variable trick should be secure, if I understand correctly.
Steve : environment is NOT secure (it’s the same than passing it on the command line). A better solution should be to use .my.cnf file.
http://dev.mysql.com/doc/refman/5.0/en/password-security.html is a good source of informations about it.
Nice to see this in edge, been doing this for a while now with a simple Rake task.
@Jordi: unless you’re using this on a shared server, I don’t think it’s much of an issue. If you’re using this on your own production servers, people seeing the password in the ps list should be the last of your worries. Using it locally, I couldn’t care less if people can see my password in the ps as I use a generic password for my local database and it doesn’t contain any sensitive/important information.
In Emacs I’ve do a “C-c C-c s s RET” get the same thing … or actually better as you can’t compare a dumb prompt (readline or not) with the power of an emacs buffer.
Nice stuff!
Any security issues aside, this is a real time-saver during development.
Also, I haven’t used this particular method yet, but last time I checked when passing the MySQL password on the command-line, it obscured it, replacing the actual characters with something along the lines of ‘xxxxx’.
Cc Cc s s RET – Super combo!
Why not give mysql the -p option and then feed it the password through stdin?