10

我整天都在做这件事,我需要一些帮助。

我正在尝试为我正在从 github 处理的 RoR 项目设置 mysql 数据库。

当我尝试在终端中设置数据库时,出现以下错误:

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'

我浏览了关于 SO 的 20 个问题,但没有一个能够帮助我解决我的问题。

数据库已启动并正在运行,并且 database.yml 也已设置。

我现在有点生气......请......帮助......在为时已晚之前。

更新:我刚刚查看了我安装的 gem,并且由于某种原因它正在显示mysql2(见下文)

Eric-Reas-MacBook:~ ericrea$ gem list

*** LOCAL GEMS ***

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

这对我来说似乎有点奇怪......

更新:这是我的 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

更新:现在尝试使用自制软件重新安装 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
4

6 回答 6

20

我最终弄清楚了这一点。

我运行了以下命令:

$ mysqladmin variables | grep socket

哪个返回:

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

然后我检查了我的 database.yml 文件中的套接字位置,它是错误的:

那是错的。将其更改为正确的插座位置后,一切都像魅力一样。我希望这对将来的某人有所帮助。

于 2013-10-24T17:31:47.473 回答
13

你必须启动mysql服务器

mysql.server start

我想你可能正在寻找

rake db:migrate
于 2013-10-23T00:14:53.660 回答
3

要解决此错误,首先找到您的套接字文件,在终端中运行以下命令

mysqladmin variables | grep socket

对我来说,这给出了:

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

然后,在 config/database.yml 中添加一行:

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

这将解决这个问题。

于 2015-09-29T06:46:03.557 回答
2

尝试找到您的 MySQL 的 my.cnf 文件。在典型的 Ubuntu 服务器上,它位于:/etc/mysql/my.cnf

打开文件并确保套接字变量即 socket = /var/run/mysqld/mysqld.sock

对应于您应用程序的 database.yml 中的套接字值

于 2015-03-12T15:41:11.037 回答
1

只需简单地运行

mysql server.restart

重新启动服务器。这为我解决了这个问题。

于 2014-05-26T02:09:32.523 回答
0

我在 mysql 和我的 PHP 应用程序中遇到了类似的问题(也使用 Brew 并且还遇到了 PID 文件问题)。它是在我将 OSX 更新为 Mavericks 之后开始的,可能是系统更新覆盖了我的设置。奇怪的是,在我重新创建 /etc/php.ini 并设置正确的套接字地址指向 /tmp/mysql.sock 之后,关于 mysql 的一切都开始工作了。也许它会帮助有人在谷歌上搜索这个。

于 2013-10-23T16:45:47.630 回答