Rails Can't connect to MySQL server on 'localhost'

mysql, mysql2, ruby-on-rails

Solution

try replacing localhost with 127.0.0.1 (in workbench and yml)

Problem

I'm having no end of trouble with my Rails 3 app's Mysql connection, though I have studied countless relevant threads. My error message: ``` C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysql2::Error) ``` (Before you flag this as a duplicate question, consider whether you can find another thread with pertinent advice I have not followed.) My efforts thus far: I have copied the libmysql.dll file from `<mysql installation>/bin` to `<ruby installation>/bin`. I have the mysql2 gem in the bundle, and it was installed with the connector (`--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32`): ``` > bundle show mysql2 C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32 ``` I believe my database.yml file is configured correctly: ``` development: adapter: mysql2 encoding: utf8 reconnect: false database: tq_development pool: 5 username: root password: pinney host: localhost ```

Original source