【发布时间】:2011-11-10 18:39:00
【问题描述】:
我是 Web 开发和 RoR 的新手 - 超级菜鸟! - 我正在通过 lynda.com 参加在线 RoR 课程。很高兴加入 StackOverflow 社区,并且非常感谢您在路障方面的一些帮助。
MySQL 和 localhost 在我设置我的基本应用程序并成功运行了一些迁移时工作了好几个星期,但是今天当我启动我的 Rails 服务器并在浏览器中查看 http://localhost:3000/ 时,我收到了这个 MySQL 错误:
Mysql2::Error (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
我认为我没有更改与我的环境相关的任何内容,所以我想知道是否需要更新 gems 或类似的简单内容?
我已经在 Google 和 StackOverflow 上搜索了几个小时,但仍然无法弄清楚这里出了什么问题以及如何解决它。其他解决方案似乎与新设置有关,而不是莫名其妙地中断的工作设置。
这里有一些上下文:
来自我的 config/database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: XXXXXXXXX
socket: /tmp/mysql.sock
我保存了几周前 MySQL 和 localhost 工作正常时的命令行:
Last login: Mon Aug 15 21:34:23 on ttys000
sdemessieres$ cd sites/simple_cms
sdemessieres$ pwd
/Users/sdemessieres/sites/simple_cms
sdemessieres$ rails server
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-08-22 22:28:01] INFO WEBrick 1.3.1
[2011-08-22 22:28:01] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0]
[2011-08-22 22:28:01] INFO WEBrick::HTTPServer#start: pid=66952 port=3000
Started GET "/" for 127.0.0.1 at Mon Aug 22 22:28:20 -0400 2011
Processing by DemoController#index as HTML
等...(从这里工作正常)
但是今天我尝试了相同的命令并收到错误:
Last login: Mon Sep 5 12:13:22 on ttys000
sdemessieres$ cd sites/simple_cms
sdemessieres$ pwd
/Users/sdemessieres/sites/simple_cms
sdemessieres$ rails server
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-09-05 12:33:09] INFO WEBrick 1.3.1
[2011-09-05 12:33:09] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0]
[2011-09-05 12:33:09] INFO WEBrick::HTTPServer#start: pid=11027 port=3000
Started GET "/" for 127.0.0.1 at Mon Sep 05 12:33:41 -0400 2011
Mysql2::Error (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.7ms)
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (6.3ms)
所以我回到了培训中的数据库笔记,并尝试从我的命令行连接到 MySQL,这在以前可以工作但不再有效:
sdemessieres$ pwd
/Users/sdemessieres/sites/simple_cms
sdemessieres$ which mysql
/usr/local/mysql/bin/mysql
sdemessieres$ mysql --version
mysql Ver 14.14 Distrib 5.5.13, for osx10.6 (i386) using readline 5.1
sdemessieres$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
sdemessieres$
一个 StackOverflow thread 给了我这个线索,但它似乎只是强化了我的设置是正确的。
sdemessieres$ mysql_config |grep -- --socket
--socket [/tmp/mysql.sock]
正如我所说,我是一个完全的初学者,所以任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: mysql ruby-on-rails-3