MySQL configured to use tunneled localhost port

5 views
Skip to first unread message

Jb Smith

unread,
Oct 27, 2007, 11:20:15 AM10/27/07
to rubyonra...@googlegroups.com
Today I discovered an interesting behavior of the mysql database adapter
when connecting to a tunneled localhost port for MySQL from OSX.

i started a tunnel using the usual ssh command line options:

ssh -p 22 -L 3307:localhost:3306 us...@remotehost.domain.com

then in database.yml
THIS WORKS

development:
adapter: mysql
encoding: utf8
database: dev_data
username: dev_admin
password: password
host: 127.0.0.1
port: 3307

THIS FAILS
development:
adapter: mysql
encoding: utf8
database: dev_data
username: dev_admin
password: password
host: localhost
port: 3307

It seems that the adapter will automatically force a mysql.sock to be
used when host: is set to localhost.
Switching host: to the actual IP seems to allow the port option to go
into effect.

Just wanted to post this so others may find the solution I did, more
quickly.
--
Posted via http://www.ruby-forum.com/.

Andrew Vit

unread,
Oct 27, 2007, 7:26:46 PM10/27/07
to rubyonra...@googlegroups.com
On 2007-10-27 08:20:15 -0700, Jb Smith
<rails-mai...@andreas-s.net> said:

> THIS WORKS
> host: 127.0.0.1
>
> THIS FAILS
> host: localhost


>
> It seems that the adapter will automatically force a mysql.sock to be
> used when host: is set to localhost.

Yes, I've noticed this myself; it's not particular to Rails. I have to
do this when using CocoaMySQL to connect to my remote database via ssh
tunnel. I sure would like to know why it works this way too... Is
"localhost" just a magic keyword for using the socket?

--Andrew Vit


Roger Pack

unread,
Jan 7, 2008, 6:56:24 PM1/7/08
to rubyonra...@googlegroups.com
Thank you! That is exactly how to get ruby mysql to run on a port
instead of on the unix socket. Odd that it would be necessary.
Note also that for mysql command line to work with 'just a socket' and
not automatically use the port, you need to run
mysql -uwhatever -p --protocol=tcp --port=whatever # or it won't use the
port, only uses the local socket (at least on os x).
Thank you.
-Roger

> then in database.yml
> THIS WORKS
>
> development:
> adapter: mysql
> encoding: utf8
> database: dev_data
> username: dev_admin
> password: password
> host: 127.0.0.1
> port: 3307

Reply all
Reply to author
Forward
0 new messages