Question

I've been using Emacs's sql interactive mode to talk to the MySQL db server and gotten to enjoy it. A developer has set up another db on a new non-default port number but I don't know how to access it using sql-mysql.

How do I specify a port number when I'm trying to connect to a database?

It would be even better if Emacs can prompt me for a port number and just use the default if I don't specify. Any chances of that?

Was it helpful?

Solution

After digging through the sql.el file, I found a variable that allows me to specify a port when I try to create a connection.

This option was added GNU Emacs 24.1.

sql-mysql-login-params

List of login parameters needed to connect to MySQL.

I added this to my Emacs init file:

(setq sql-mysql-login-params (append sql-mysql-login-params '(port)))

The default port is 0. If you'd like to set that to the default MySQL port you can customize sql-port

(setq sql-port 3306) ;; default MySQL port

There is a sql-*-login-params variable for all the popular RDMS systems in GNU Emacs 24.1. sql-port is used for both MySQL and PostreSQL

OTHER TIPS

(setq sql-mysql-options (list "-P <port number>"))

I found the option using:

M-x customize-group
SQL

That included a setting labeled:

Mysql Options:

If you set the option and save it, there will be a new line added to your .emacs:

(custom-set-variables
 '(sql-mysql-options (quote ("-P ???"))))

(Obviously, you ought to use the actual port number.)

I use XEmacs, so your mileage may vary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top