# Interacting with a MySQL database

**URL:** <https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388>\
**Category:** Rails\
**Created:** [October 24, 2006, 10:00am UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388 "2006-10-24T10:00:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [October 24, 2006, 10:00am UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/1 "2006-10-24T10:00:42Z")

</div>

Hi, I am on a OSX and have installed locomotive. I am competant enough  
at the momnent to create projects, controllers, models etc through  
terminal, however I am finding it hard to connect to a MySQL database.  
In the database config file I have set the username and password  
correctly but is still giving me an error. The error is somewhere along  
the lines of this (I am not 100% sure as I am not at my Mac at the  
moment):

Could not connect to mysql database on temp/socket (2)

Now, I think I might know why it isn’t working, but am not sure how to  
fix it. I am using MySQL from a MAMP installation, and Ruby with  
Locomotive (as previously stated). Ruby is running on port 3000, and  
MySQL on 8889 (I think). Do I need to change anything in the database  
connection info to allow for this, or should it be done automatically?

Thanks,  
virtual.

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [October 24, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/2 "2006-10-24T14:59:02Z")

</div>

Hi Virgil,

Sounds like you need to add a “socket: /path/to/mysql.sock” line in your  
database.yml file. E.g.

development:  
adapter: mysql  
database: db\_development  
username: ruby  
password: ruby  
host: localhost  
socket: /var/lib/mysql/mysql.sock

Of course, I’m speaking from a Linux perspective. Your milage may vary.

Virgil Tual wrote:

> Hi, I am on a OSX and have installed locomotive. I am competant enough  
> at the momnent to create projects, controllers, models etc through  
> terminal, however I am finding it hard to connect to a MySQL database.  
> In the database config file I have set the username and password  
> correctly but is still giving me an error. The error is somewhere along  
> the lines of this (I am not 100% sure as I am not at my Mac at the  
> moment):
> 
> Could not connect to mysql database on temp/socket (2)
> 
> Now, I think I might know why it isn’t working, but am not sure how to  
> fix it. I am using MySQL from a MAMP installation, and Ruby with  
> Locomotive (as previously stated). Ruby is running on port 3000, and  
> MySQL on 8889 (I think). Do I need to change anything in the database  
> connection info to allow for this, or should it be done automatically?
> 
> Thanks,  
> virtual.

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [October 24, 2006, 8:18pm UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/3 "2006-10-24T20:18:34Z")

</div>

Thanks Colin, however that sadly didn’t work - still displayed the same  
error.

Now that I am home I can give you some more detailed information. This  
is my current database.yml file:

development:  
adapter: mysql  
database: blog\_development  
username: root  
password: root  
host: localhost  
socket: /var/lib/mysql/mysql.sock

The database exists, and MAMP is running with MySQK on port 8888 (I have  
tried adding Port: 8888 in the file wih again, no luck). The mysqld  
process is also running.

I am running Locomotive2 and following the 15 minute blog tutorial on  
the rails site ([Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.](http://www.rubyonrails.org/screencasts)). Everything was  
going smoothly until the dreaded database connection ☹

And help would be appreciated, starting to pull my hair out.  
Thanks,  
virtual

Colin Wu wrote:

> Hi Virgil,
> 
> Sounds like you need to add a “socket: /path/to/mysql.sock” line in your  
> database.yml file. E.g.
> 
> development:  
> adapter: mysql  
> database: db\_development  
> username: ruby  
> password: ruby  
> host: localhost  
> socket: /var/lib/mysql/mysql.sock

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [October 29, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/4 "2006-10-29T20:33:32Z")

</div>

Virgil Tual wrote:

> Sorry, might help if I add the error messgae:
> 
> Mysql::Error in BlogController#index
> 
> Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
> 
> RAILS\_ROOT: /Users/chris/Ruby/Blog/public/…/config/…

i had the same problem  
i don’t know why but the only socet file i found on my mac was  
mysql-vcw.sock

so i just changed my database yml to include

socket: /tmp/mysql-vcw.sock

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [October 24, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/5 "2006-10-24T20:20:10Z")

</div>

Sorry, might help if I add the error messgae:

Mysql::Error in BlogController#index

Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

RAILS\_ROOT: /Users/chris/Ruby/Blog/public/…/config/…

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [November 7, 2006, 10:47am UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/6 "2006-11-07T10:47:25Z")

</div>

aaron wrote:

> i don’t know why but the only socet file i found on my mac was  
> mysql-vcw.sock
> 
> so i just changed my database yml to include
> 
> socket: /tmp/mysql-vcw.sock
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

as written in original post he is running MAMP and MAMP will only be in  
one location: /Application/MAMP  
so the socks file also must be there. in my case it is under  
/Applications/MAMP/tmp/mysql. so I added the following line to  
database.yml and it woks:  
socket: /Applications/MAMP/tmp/mysql/mysql.sock

hope this helps  
Fritzek

---

<div class="post-metadata">

**Author:** ![virtual](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@virtual](https://www.ruby-forum.com/u/virtual)\
**Post date:** [November 7, 2006, 10:47am UTC](https://www.ruby-forum.com/t/interacting-with-a-mysql-database/73388/7 "2006-11-07T10:47:33Z")

</div>

aaron wrote:

> i don’t know why but the only socet file i found on my mac was  
> mysql-vcw.sock
> 
> so i just changed my database yml to include
> 
> socket: /tmp/mysql-vcw.sock
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

as written in original post he is running MAMP and MAMP will only be in  
one location: /Application/MAMP  
so the socks file also must be there. in my case it is under  
/Applications/MAMP/tmp/mysql. so I added the following line to  
database.yml and it woks:  
socket: /Applications/MAMP/tmp/mysql/mysql.sock

hope this helps  
Fritzek
