Home > Database > Mysql Tutorial > 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
Release: 2024-11-09 04:48:02
Original
785 people have browsed it

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
Copy after login

For instance, it may return:

| socket                                            | /tmp/mysql.sock                                                                                                        |
Copy after login
  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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template