无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器 [英] Can't connect to local MySQL server through socket '/tmp/mysql.sock'

查看:123
本文介绍了无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web开发和RoR的新手,这是一个新手! -我正在通过lynda.com进行在线RoR课程.很高兴加入StackOverflow社区,并非常感谢您提供一些帮助.

I am brand-new to web development and RoR - an uber-noob! - and I'm taking an online RoR course via lynda.com. Excited to join the StackOverflow community, and would really appreciate some help with a roadblock.

当我安装基本应用程序并成功运行一些迁移时,MySQL和localhost运行了几周,但是今天,当我启动Rails服务器并在

MySQL and localhost were working fine for several weeks as I set up my rudimentary app and successfully ran some migrations, but today I am getting this MySQL error when I launch my rails server and view on http://localhost:3000/ in my browser:

Mysql2 :: Error(无法通过套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器):

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

我认为我没有更改与环境相关的任何内容,因此我想知道是否需要更新gem或类似的简单内容?

I don't think I've changed anything relevant in my environment, so I wonder if I need to update gems or something simple like that?

我已经在Google和StackOverflow上搜寻了两个小时,但仍然不知道这里出了什么问题以及如何解决.其他解决方案似乎与新的设置有关,而不是与无法解释的工作设置相对.

I've hunted around on Google and StackOverflow for a couple hours now and still can't figure out what went wrong here and how to fix it. Other solutions seem to relate to new set-ups as opposed to a working set-up that inexplicably breaks.

这里是一些上下文:

在我的config/database.yml中:

From 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运行正常的命令行:


I saved a command line from a couple weeks ago when MySQL and localhost were working fine:

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

等...(在这里工作正常)

etc... (worked fine from here)

但是今天我尝试了相同的命令并收到错误消息:

But then today I tried the same commands and receive the error:

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:


So I went back to the database notes from my training and tried connecting to MySQL from my command line which had worked before but no longer:

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 线程给了我这个线索,但是它似乎只是在强调我的设置是正确的.


One StackOverflow thread gave me this clue but it only seems to reinforce that my set up is correct.

sdemessieres$ mysql_config |grep -- --socket
        --socket         [/tmp/mysql.sock]


正如我说的,我是一个初学者,所以非常感谢您的帮助!


As I said, I am a total beginner so any help would be much appreciated, thanks!

推荐答案

这个问题有些过时,但是我在研究类似问题时遇到了它.使用mysql_config命令确认套接字的位置和名称有助于解决我的问题.

This question is somewhat dated, but it I came across it while researching a similar issue. Confirming the socket location and name with the mysql_config command was instrumental in resolving my problem.

我遇到了同样的错误,并且已经调整了config/database.yml中的套接字入口路径以匹配找到.sock文件的位置.

I was getting the same error and had adjusted the socket entry path in config/database.yml to match where I found the .sock file.

但是,除了路径更改之外,我的database.yml文件中的套接字条目也称为"mysql.sock",与我在搜索过程中与该问题有关的大多数讨论一样.

However beyond the path change, the socket entry in my database.yml file referred to "mysql.sock", as do most of the discussions related to this issue during my search.

mysql_config的输出略有不同.它显示文件名是"mysqld.sock" ...注意'd',而不是mysql.sock.我错过了它,因为我专注于这条路.

The output of mysql_config was slightly different. It revealed that the file name was "mysqld.sock"...notice the 'd', not mysql.sock. I missed it because I was focussing on the path.

mysql安装仅在服务器上的VPS,没有客户端上,这可能解释了套接字文件名的差异.

The mysql installation is on a server only VPS, no client, which may explain the difference in the socket file name.

这篇关于无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆