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:
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 |
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!