MySQL configured to use tunneled localhost port

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 [email protected]

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.

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

On 2007-10-27 08:20:15 -0700, Jb Smith
[email protected] 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 V.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs