# ActiveRecord will not change port

**URL:** <https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753>\
**Category:** Rails\
**Created:** [November 10, 2009, 9:23pm UTC](https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753 "2009-11-10T21:23:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpiskorz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mpiskorz](https://www.ruby-forum.com/u/mpiskorz)\
**Post date:** [November 10, 2009, 9:23pm UTC](https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753/1 "2009-11-10T21:23:31Z")

</div>

Hello,

I’m trying to connect to a remote mysql server using a ssh tunnel and  
activerecord.

I know the ssh tunnel is working because I can connect via the cmd  
line client.  
I’ve set the ssh tunnel up like this: ssh -L 3307:127.0.0.1:3306.

So, I thought I could just change the port on my active record  
connection, but it still connects to my local mysql server.

class MyClass \< ActiveRecord::Base  
establish\_connection(  
:adapter =\> ‘mysql’,  
:user =\> ‘root’,  
:database =\> ‘hrsuite\_production’,  
:server =\> “127.0.0.1”,  
:port =\> 3307)

I’ve also tried :server =\> ‘127.0.0.1:3307’ but that did not work  
either. I also tried :socket =\> nil, but no luck.

I’m running active record 2.3.4

Any suggestions and thanks for taking a look,

Matt

---

<div class="post-metadata">

**Author:** ![mpiskorz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mpiskorz](https://www.ruby-forum.com/u/mpiskorz)\
**Post date:** [November 11, 2009, 12:53pm UTC](https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753/2 "2009-11-11T12:53:14Z")

</div>

mpiskorz wrote:

> class MyClass \< ActiveRecord::Base  
> establish\_connection(  
> :adapter =\> ‘mysql’,  
> :user =\> ‘root’,  
> :database =\> ‘hrsuite\_production’,  
> :server =\> “127.0.0.1”,  
> :port =\> 3307)
> 
> I’ve also tried :server =\> ‘127.0.0.1:3307’ but that did not work  
> either. I also tried :socket =\> nil, but no luck.

Try :host instead of :server .

---

<div class="post-metadata">

**Author:** ![mpiskorz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mpiskorz](https://www.ruby-forum.com/u/mpiskorz)\
**Post date:** [November 11, 2009, 4:44pm UTC](https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753/3 "2009-11-11T16:44:12Z")

</div>

Aldric,

Thanks a lot! That was it.

I don’t know how many times I looked at the API yesterday, but there  
it was. Thanks for catching it.

By chance, do you know what the difference is between using host and  
server?

Thanks again!  
Matt

On Nov 11, 5:53 am, Aldric G. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![mpiskorz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mpiskorz](https://www.ruby-forum.com/u/mpiskorz)\
**Post date:** [November 11, 2009, 4:49pm UTC](https://www.ruby-forum.com/t/activerecord-will-not-change-port/178753/4 "2009-11-11T16:49:45Z")

</div>

mpiskorz wrote:

> I don’t know how many times I looked at the API yesterday, but there  
> it was. Thanks for catching it.  
> You’re welcome 🙂
> 
> By chance, do you know what the difference is between using host and  
> server?

You mean, besides the fact that host works and server doesn’t? 😉  
I’m guessing that, in the absence of a valid :host option, it tries to  
connect to localhost.
