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:
mysqladmin variables | grep socket
socket: /tmp/mysql.sock
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
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!