简体   繁体   English

在为Ruby on Rails应用程序设置mysql数据库时出现“无法通过套接字连接到本地MySQL服务器'/var/run/mysqld/mysqld.sock'”错误

[英]Getting “Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'” error when setting up mysql database for Ruby on Rails app

I have been working on this all day long, and I need some help. 我整天都在努力,我需要一些帮助。

I am trying to setup the mysql database for a RoR project I'm working on from github. 我正在尝试为我正在从github工作的RoR项目设置mysql数据库。

When I try to setup the db in the terminal, I get the following error: 当我尝试在终端中设置数据库时,我收到以下错误:

Eric-MacBook:~ eric$ cd ~/review_rocket
Eric-MacBook:review_rocket eric$ rake db:setup
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

I have looked through 20 questions on SO, and none have been able to help me solve my problem. 我已经查看了20个关于SO的问题,但没有一个能够帮助我解决我的问题。

The database is up and running, and the database.yml is set up too. 数据库已启动并正在运行,并且还设置了database.yml。

I am currently going a little mad... please... help...before it's too late. 我现在有点生气了......拜托......帮助......为时已晚。

UPDATE: I just looked at my installed gems, and for some reason it's showing mysql2 (see below) 更新:我只看了我安装的宝石,由于某种原因,它显示了mysql2 (见下文)

Eric-Reas-MacBook:~ ericrea$ gem list

*** LOCAL GEMS ***

multi_json (1.8.2)
mysql2 (0.3.13)
net-sftp (2.1.2) 

That seems a little odd to me... 这对我来说有点奇怪......

Update: Here is what my database.yml is looking like: 更新:这是我的database.yml看起来像:

common: &common
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  user_name: xxxx
  password: xxxx
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *common
  database: dev_review_rocket

# Warning: The database defined as "money_tracker_test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *common
  database: test_review_rocket

production:
  <<: *common
  database: prod_review_rocket

UPDATE: Now getting weird errors when trying to reinstall mysql with homebrew (see below): 更新:现在尝试使用自制软件重新安装mysql时出现奇怪的错误(见下文):

$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.13.mountain_lion.bottle.1.tar.gz
==> Pouring mysql-5.6.13.mountain_lion.bottle.1.tar.gz
==> /usr/local/Cellar/mysql/5.6.13/bin/mysql_install_db --verbose --user=ericrea
2013-10-22 18:32:41 56901 [Note] InnoDB: FTS optimize thread exiting.
2013-10-22 18:32:41 56901 [Note] InnoDB: Starting shutdown...
2013-10-22 18:32:42 56901 [Note] InnoDB: Shutdown completed; log sequence number 1626067
2013-10-22 18:32:42 56901 [Note] /usr/local/Cellar/mysql/5.6.13/bin/mysqld: Shutdown complete

Warning: mysql post_install failed. Rerun with `brew postinstall mysql`.
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/5.6.13: 9382 files, 354M
Eric-Reas-MacBook:~ ericrea$ brew postinstall mysql
==> /usr/local/Cellar/mysql/5.6.13/bin/mysql_install_db --verbose --user=ericrea
2013-10-22 18:33:22 57135 [Note] InnoDB: FTS optimize thread exiting.
2013-10-22 18:33:22 57135 [Note] InnoDB: Starting shutdown...
2013-10-22 18:33:23 57135 [Note] InnoDB: Shutdown completed; log sequence number 1626087
2013-10-22 18:33:23 57135 [Note] /usr/local/Cellar/mysql/5.6.13/bin/mysqld: Shutdown complete


READ THIS: https://github.com/mxcl/homebrew/wiki/troubleshooting

These open issues may also help:
    https://github.com/mxcl/homebrew/issues/22021
    https://github.com/mxcl/homebrew/pull/22480

I ended up figuring this one out. 我最终想出了这个。

I ran the following command: 我运行了以下命令:

$ mysqladmin variables | grep socket

Which returned: 返回的是:

| performance_schema_max_socket_classes                  | 12                                                                                                                                                                                                                                                                                                                                               |
| performance_schema_max_socket_instances                | 323                                                                                                                                                                                                                                                                                                                                              |
| socket                                                 | /tmp/mysql.sock

Then I checked the socket location in my database.yml file and it was wrong: 然后我检查了我的database.yml文件中的套接字位置,这是错误的:

It was wrong. 那是错的。 After changing it to the right socket location everything worked like a charm. 将它更换到正确的插座位置后,一切都像魅力一样。 I hope this helps someone in the future. 我希望这可以帮助将来的某个人。

You have to start the mysql server 你必须启动mysql服务器

mysql.server start

and I think you may be looking for 我想你可能正在寻找

rake db:migrate

Try and find your MySQL's my.cnf file. 试着找到你的MySQL的my.cnf文件。 On a typical Ubuntu server it is at: /etc/mysql/my.cnf 在典型的Ubuntu服务器上,它位于:/etc/mysql/my.cnf

Open the file and make sure that the socket variable ie socket = /var/run/mysqld/mysqld.sock 打开文件并确保套接字变量ie socket = /var/run/mysqld/mysqld.sock

corresponds to your socket value in your apps' database.yml 对应于应用程序的database.yml中的套接字值

Just simply run 只是简单地跑

mysql server.restart

to restart the server. 重启服务器。 This fixed this issue for me. 这为我解决了这个问题。

To solve this error first find your socket file, run the following commands in terminal 要解决此错误,请先找到您的套接字文件,在终端中运行以下命令

mysqladmin variables | grep socket

For me, this gives: 对我来说,这给了:

| socket              | /var/run/mysqld/mysqld.sock

Then, add a line to your config/database.yml: 然后,在config / database.yml中添加一行:

development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock

This will solve this problem. 这将解决这个问题。

I had similar issue (also using Brew and also getting PID file problem) with mysql and my PHP app. 我有类似的问题(也使用Brew,也得到PID文件问题)与mysql和我的PHP应用程序。 It started after I updated the OSX to Mavericks, probably the system update overrided my settings. 它是在我将OSX更新为Mavericks之后开始的,可能是系统更新覆盖了我的设置。 Strangely, everything regarding mysql started to work again after I recreated /etc/php.ini and set proper socket address pointing to /tmp/mysql.sock. 奇怪的是,在我重新创建/etc/php.ini并设置指向/tmp/mysql.sock的正确套接字地址后,关于mysql的所有内容都重新开始工作。 Maybe it'll help someone googling for this. 也许它会帮助谷歌搜索这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 出现错误:无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器(2) - Getting error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) mysql错误“无法通过套接字&#39;/var/run/mysqld/mysqld.sock连接到本地MySQL服务器” - mysql error “Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock” 无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器(错误2002) - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (error 2002) 错误:无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器 (2) - Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 错误:'无法通过套接字 '/var/run/mysqld/mysqld.sock' (2)' 连接到本地 MySQL 服务器 - 缺少 /var/run/mysqld/mysqld.sock - error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock 系统更新后出现错误:“无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器” - After system update getting error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' 从终端运行flask应用程序时,无法通过套接字&#39;/var/run/mysqld/mysqld.sock连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock when running flask app from terminal 无法通过ubuntu 14.04中的套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in ubuntu 14.04 “无法通过套接字&#39;/var/run/mysqld/mysqld.sock&#39;(2)连接到本地MySQL服务器”) - “Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)”) django无法通过套接字&#39;/var/run/mysqld/mysqld.sock连接到本地MySQL服务器 - django Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM