小编典典

Ruby on Rails 3无法通过OSX上的套接字'/tmp/mysql.sock'连接到本地MySQL服务器

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

运行rake db:migrate创建数据库时出现的错误是:

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

config / database.yml有

development:
  adapter: mysql2
  host: localhost
  username: root
  password: xxxx
  database: xxxx

确保这是我想念的简单事情。


阅读 237

收藏
2020-05-17

共1个答案

小编典典

首先,找到您的套接字文件:

mysqladmin variables | grep socket

对我来说,这给出了:

| socket                                            | /tmp/mysql.sock                                                                                                        |

然后,在您的添加一行config/database.yml

development:
  adapter: mysql2
  host: localhost
  username: root
  password: xxxx
  database: xxxx
  socket: /tmp/mysql.sock
2020-05-17