Home  >  Article  >  Database  >  How to Fix 'Can't connect to local MySQL server through socket' Error in Rails 3?

How to Fix 'Can't connect to local MySQL server through socket' Error in Rails 3?

Susan Sarandon
Susan SarandonOriginal
2024-11-09 04:48:02751browse

How to Fix

Ruby on Rails 3: Troubleshooting Connection to MySQL

When encountering the error "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" while running rake db:migrate, follow these steps for troubleshooting:

  1. Locate Your Socket File:

Execute the following command to determine the location of your MySQL socket file:

mysqladmin variables | grep socket

For instance, it may return:

| socket                                            | /tmp/mysql.sock                                                                                                        |
  1. Modify Configuration File:

In your config/database.yml file, add a new line to specify the socket file path:

development:
  adapter: mysql2
  host: localhost
  username: root
  password: xxxx
  database: xxxx
  socket: /tmp/mysql.sock

Replace /tmp/mysql.sock with the path you found in Step 1.

The above is the detailed content of How to Fix 'Can't connect to local MySQL server through socket' Error in Rails 3?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn