2
votes

I'm trying to set up a Rails application to use a MySQL server on my local machine for development. I have successfully compiled the mysql2 gem against MySQLConnector/C; although I have received the same error using libmysql.dll bundled with my installation of MySQL Server. When I attempt to rake db:create, the application fails to connect to the MySQL Server.

MySQL is configured on my machine as a Windows service, started automatically for local-only connections through named-pipes; TCP-IP has been completely disabled. The name of the socket in my my.ini file is mysql.

My database.yml file for my Rails application looks something like this:

development:
adapter: mysql2
encoding: utf8 reconnect: false
database: application_dev
pool: 5
username: root

password: **********

host: localhost
socket: mysql

test:
adapter: mysql2
encoding: utf8 reconnect: false
database: application_test pool: 5
username: root

password: **********

host: localhost
socket: mysql

And the error I'm recieving is:

D:\Dropbox\Programming\Ruby\application>rake db:create (in D:/Dropbox/Programming/Ruby/application) Can't connect to MySQL server on 'localhost' (10061) Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"application_test", "pool"=>5, "username"=>"root", "password"=>"**********", "host"=>"localhost", " socket"=>"mysql"}, charset: utf8, collation: utf8_unicode_ci

Can't connect to MySQL server on 'localhost' (10061) Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnec t"=>false, "database"=>"applicaton_dev", "pool"=>5, "username"=>"root", "password "=>"**********", "host"=>"localhost", "socket"=>"mysql"}, charset: utf8, collation: utf8_unicode_ci

I'm using Windows 7 Home Premium 64-bit with the following Ruby/Rails/MySQL distribution:

ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

Rails 3.0.7

mysql2 rubygem 0.2.7

mysql Ver 14.14 Distrib 5.5.11, for Win32 (x86)

mysql Connector/C 6.0.0

I've tried reinstalling MySQL Server and enabling TCP-IP connections, and it just hangs instead of failing.

1

1 Answers

0
votes

Try to specify the port number in your database.yml adding this parameter:

port: 3306 (or whatever your mysql port has)