<p>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.</p>

<p>How do I specify a port number when I'm trying to connect to a database?</p>

<p>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?</p>

[{'answer_id': 12628, 'author': 'Marcel Levy', 'author_id': 676, 'author_profile': 'https://Stackoverflow.com/users/676', 'pm_score': 3, 'selected': False, 'text': '<pre><code>(setq sql-mysql-options (list "-P &lt;port number&gt;"))\n</code></pre>\n'}, {'answer_id': 12658, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 3, 'selected': False, 'text': '<p>I found the option using:</p>\n\n<pre><code>M-x customize-group\nSQL\n</code></pre>\n\n<p>That included a setting labeled:</p>\n\n<pre><code>Mysql Options:\n</code></pre>\n\n<p>If you set the option and save it, there will be a new line added to your .emacs:</p>\n\n<pre><code>(custom-set-variables\n \'(sql-mysql-options (quote ("-P ???"))))\n</code></pre>\n\n<p>(Obviously, you ought to use the actual port number.)</p>\n\n<p>I use XEmacs, so your mileage may vary.</p>\n'}, {'answer_id': 12538719, 'author': 'Cristian', 'author_id': 680, 'author_profile': 'https://Stackoverflow.com/users/680', 'pm_score': 5, 'selected': True, 'text': "<p>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.</p>\n<p>This option was added GNU Emacs 24.1.</p>\n<blockquote>\n<p><strong>sql-mysql-login-params</strong></p>\n<p>List of login parameters needed to connect to MySQL.</p>\n</blockquote>\n<p>I added this to my Emacs init file:</p>\n<pre><code>(setq sql-mysql-login-params (append sql-mysql-login-params '(port)))\n</code></pre>\n<p>The default port is 0. If you'd like to set that to the default MySQL port you can customize <code>sql-port</code></p>\n<pre><code>(setq sql-port 3306) ;; default MySQL port\n</code></pre>\n<p>There is a <code>sql-*-login-params</code> variable for all the popular RDMS systems in GNU Emacs 24.1. <code>sql-port</code> is used for both MySQL and PostreSQL</p>\n"}]
['https://Stackoverflow.com/questions/12613', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/680/']