Forum: Ruby Mysql Database connection Error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
80eed0dd4d0b9b3ce85e30f0e1bb13e7?d=identicon&s=25 Maserati Njambi (maserati)
on 2014-05-02 12:13
Hi , i am new to ruby, i seem to have a problem connecting to my mysql
database, i keep getting this error, {Error code:
2002
Error message: Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)}
- i use ubuntu 12.04.
please assist!
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2014-05-04 04:07
1) Did you install 'the mysql database server'?  That isn't the same
thing as the mysql2 ruby gem.  The mysql2 ruby gem just allows
your ruby code to talk to 'the mysql database server'.  To
download 'the mysql database server' go here:

http://dev.mysql.com/downloads/

You want to download the free community version.

2) If you already installed 'the mysql database server', then you have
to start it before running your ruby program.  Once again, the mysql2
ruby gem just allows you to talk to 'the mysql database server'.  If
there is no one on the other end of the phone, your ruby program has no
one to talk to.   To start 'the mysql database server', check the README
file.  Mine contains these instructions:

For startup:

     shell> cd /usr/local/mysql
     shell> sudo ./bin/mysqld_safe
     (ENTER YOUR PASSWORD, IF NECESSARY)
     (PRESS CONTROL-Z)
     shell> bg
     (PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL)

SHUTDOWN:
     $ cd /usr/local/mysql
     $ sudo mysqladmin shutdown

If I run a ruby mysql program without starting 'the mysql database
server' beforehand, I get the following error:


/Users/7stud/.rvm/gems/ruby-1.9.3-p194@programming/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in
`connect': Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) (Mysql2::Error)
This topic is locked and can not be replied to.