After working quite a time with some minor MySQL databases in the (Emacs-) Terminal I just looked up the preinstalled SQL related emacs functions. Just entered
M-x sql TAB and indeed the autocompletion showed a function sql-mysql, as expected…
I gave it a try with
and after prompting for database, servername, username and password Emacs connected to the database and presented the MySQL shell. So I bound sql-mysql to some keyboard shortcut, BUT entering the whole connection parameters each and every time was not acceptable.
Atomized.org has a really nice post on Enhancing Emacs’ SQL Mode (you can have a look, but you cannot read the post before pasting the content to a text editor). There I found some excellent functions which would provide a solution:
(defun sql-connect-preset (name)
"Connect to a predefined SQL connection listed in `sql-connection-alist'"
(eval `(let ,(cdr (assoc name sql-connection-alist))
(flet ((sql-get-login (&rest what)))
(defun sql-pool-a ()
Now, you can just run sql-pool-a and get connected right away. Because the buffers have good names, you can easily fire up many connections.
I included it in my .emacs file and appended
(DefGlobKey "s-a" 'sql-pool-a)
and with a keystroke the database promt appears.
but what’s that webpage giving you an epileptic fit looking at it?!. Excellent page 🙂
6 thoughts on “Emacs as MySQL frontend”
I don’t know what you mean, my site looks just fine to me.
Oops, that‘s true. Beautiful page – when I opened it in Chrome today.
When I wrote the post, I did use IE8 on my job machine (the firewall does not accept anything else) the background was displayed as “dancing stars” the whole site was displayed as a “christmas on LSD” firework and the fond was completely vanishing….
Maybe it was a red hering, but I will try to reproduce it, make a screenshot and notify you.
Excellent work by the way atomized.org. Really appreciated!
Ok, it is consistent… reproduced the bug on 2 different XP/IE8 at work… atomized.org gets messed up by IE8…
Sounds like an IE bug.
Are there any security issues with having your user name in password in your .emacs file? Do you take other measures to keep them secure?
Yes, there are of course security issues if the datatables contain sensitive information, which is not the case for me. Anyway it is important to do
chmod 600 .emacsso that you are the only user (and root of course) who can read/write the .emacs file. If the data in the database is highly sensitive, I would not include the password in the .emacs file.