我一整天都在为这个工作,我需要一些帮助。
我正在尝试为我从github开发的一个RoR项目设置mysql数据库。
当我试图在终端中设置db时,会得到以下错误:
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'我看了20个问题,没有一个能帮我解决问题。
数据库已启动并正在运行,database.yml也已设置。
我现在有点疯狂..。请..。help...before,太晚了。
更新:我刚刚查看了我安装的宝石,由于某种原因,它显示了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发布于 2013-10-24 17:31:47
最后我想出了这个问题。
我运行了以下命令:
$ mysqladmin variables | grep socket返回:
| performance_schema_max_socket_classes | 12 |
| performance_schema_max_socket_instances | 323 |
| socket | /tmp/mysql.sock然后,我检查了我的database.yml文件中的套接字位置,这是错误的:
,这是错的。在将其更改为正确的套接字位置后,一切都像魅力一样工作。我希望这对将来的人有帮助。
发布于 2013-10-23 00:14:53
您必须启动mysql服务器。
mysql.server start我想你可能是在寻找
rake db:migrate发布于 2015-09-29 06:46:03
若要解决此错误,请先查找套接字文件,在终端中运行以下命令
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这将解决这个问题。
https://stackoverflow.com/questions/19530089
复制相似问题