Interacting with a MySQL database

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.

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.

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 (http://www.rubyonrails.org/screencasts). Everything was
going smoothly until the dreaded database connection :frowning:

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

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

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/…

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

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

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

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

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