Ruby on Rails 3 无法通过 OSX 上的套接字“/tmp/mysql.sock"连接到本地 MySQL 服务器
我有一个标准的 Rails3 环境,RVM 1.2.9,Rails 3.0.5,Ruby 1.9.2p180,MySQL2 Gem 0.2.7,mysql-5.5.10-osx10.6-x86_64
I have a standard Rails3 environment, RVM 1.2.9, Rails 3.0.5, Ruby 1.9.2p180, MySQL2 Gem 0.2.7, mysql-5.5.10-osx10.6-x86_64
运行 rake db:migrate
以创建数据库时出现的错误是:
Error I get when running rake db:migrate
to create database is:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
config/database.yml 有
config/database.yml has
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
肯定是我遗漏了一些简单的东西.
sure it's something simple I'm missing.
推荐答案
首先,找到你的socket文件:
First, to find your socket file:
mysqladmin variables | grep socket
对我来说,这给:
| socket | /tmp/mysql.sock |
然后,在您的 config/database.yml
中添加一行:
Then, add a line to your config/database.yml
:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /tmp/mysql.sock
相关文章