我是全新的网络开发和罗-一个超级noob!-我要通过lynda.com在线学习RoR课程很高兴加入StackOverflow社区,非常感谢您的帮助。
MySQL和localhost在几个星期内运行得很好,因为我安装了我的初级应用程序并成功地运行了一些迁移,但是今天当我启动rails服务器并在浏览器中查看http://localhost:3000/时,我遇到了MySQL错误:
Mysql2::错误(无法通过socket'/tmp/MySQL.sock'(2))连接到本地MySQL服务器:
我不认为我已经改变了任何与我的环境相关的东西,所以我想知道我是否需要更新gems或类似的简单的东西?
我已经在Google和StackOverflow上搜索了几个小时,仍然不知道这里出了什么问题以及如何修复它。其他解决方案似乎与新的设置有关,而不是一个工作设置,莫名其妙地打破。
下面是一些背景:
从my 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给了我这个线索,但它似乎只是在强调我的设置是正确的。
sdemessieres$ mysql_config |grep -- --socket
--socket [/tmp/mysql.sock]
如我所说,我是一个完全初学者,所以任何帮助将非常感谢,谢谢!
最佳答案
这个问题有点过时了,但我在研究一个类似的问题时发现了它。使用mysql_config
命令确认套接字的位置和名称有助于解决我的问题。
我得到了同样的错误,并调整了config/database.yml
中的套接字条目路径,以匹配找到.sock
文件的位置。
但是,除了路径更改之外,mydatabase.yml
文件中的socket条目引用了"mysql.sock"
,与搜索期间与此问题相关的大多数讨论也是如此。mysql_config
的输出略有不同。它显示文件名是"mysqld.sock"
…注意“d”,而不是mysql.sock
。我错过了,因为我正专注于这条路。mysql
安装在一个只有服务器的VPS上,没有客户端,这可能解释了套接字文件名的不同。
关于mysql - 无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7310967/