Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify a Port Number in Emacs sql-mysql

Tags:

sql

emacs

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?

like image 529
Cristian Avatar asked Aug 15 '08 19:08

Cristian


2 Answers

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

like image 85
Cristian Avatar answered Oct 12 '22 15:10

Cristian


(setq sql-mysql-options (list "-P <port number>"))
like image 27
Marcel Levy Avatar answered Oct 12 '22 14:10

Marcel Levy