Home > Database > Mysql Tutorial > body text

How to Fix 'Can't connect to local MySQL server through socket '/tmp/mysql.sock'' in Ruby on Rails 3 on OSX?

Barbara Streisand
Release: 2024-11-11 00:07:03
Original
564 people have browsed it

How to Fix

Connecting to MySQL with socket in Ruby on Rails 3 on OSX

When attempting to create a database through Ruby on Rails 3 using the rake db:migrate command, one might encounter the error: "Can't connect to local MySQL server through socket '/tmp/mysql.sock'". This error indicates an issue in establishing a connection between Rails and the MySQL server.

To resolve this issue, it is necessary to specify the socket file in the config/database.yml file:

  1. Find the socket file: Execute the following command to locate the socket file:
mysqladmin variables | grep socket
Copy after login
  1. Add the socket to config/database.yml: Open the config/database.yml file and add the following line under the "development" configuration:
socket: /tmp/mysql.sock
Copy after login

Here is an example of a complete config/database.yml configuration with the socket specified:

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

Once these steps are completed, the connection to the MySQL server should be established successfully, and the rake db:migrate command should execute without any errors.

The above is the detailed content of How to Fix 'Can't connect to local MySQL server through socket '/tmp/mysql.sock'' in Ruby on Rails 3 on OSX?. 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