Cristian
Cristian

Reputation: 43967

Specify a Port Number in Emacs sql-mysql

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?

Upvotes: 20

Views: 4219

Answers (4)

degen872
degen872

Reputation: 1

You can set the port number with M-x customize-variable which will lead to a searchable list of variables. Search for sql-mysql-options, sql-postgres-options, etc. You will enter an editable UI where you can add any flag you

Upvotes: 0

Cristian
Cristian

Reputation: 43967

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

Upvotes: 17

Marcel Levy
Marcel Levy

Reputation: 3437

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

Upvotes: 8

Jon Ericson
Jon Ericson

Reputation: 21515

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.

Upvotes: 6

Related Questions