Wednesday, September 2, 2009

MySQL Error: Can't connect to local MySQL server through socket

You try to run your Rails project and keep getting the "Can't connect to local MySQL server through socket" MySQL Error.
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:548:in `real_connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:548:in `connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:198:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:74:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:74:in `mysql_connection'

The quickest way to fix this issue is to edit the database.yml file and replace localhost with 127.0.0.1.