繁体   English   中英

Rails服务器错误

[英]Rails Server Error

我最近使用Homebrew在Mac上安装了rails。 我使用rails s启动了rails服务器,但是当我访问localhost:3000 ,出现以下错误。

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

socket = socket.to_s unless socket.nil?

      connect user, pass, host, port, database, socket, flags
    end

    def self.default_query_options

我已经用Google搜索了很多,但是找不到解决方案。

编辑:

我使用mysql.server start启动了mysql。 它开始了。 但是,当我使用mysql -u root ,它给出以下错误ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 但是在localhost:3000它给出了此错误localhost:3000 Access denied for user 'root'@'localhost' (using password: NO) 据我所记得,我没有为mysql设置任何密码。

该错误意味着Rails无法连接到数据库。 MySQL可能没有运行,或者您配置了database.yml文件。

您写的是通过Homebrew安装的MySQL。 Homebrew不会自动将MySQL配置为在系统启动时启动。 在安装结束时的输出中以及在运行brew info mysql的输出中对此进行了说明。

==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To reload mysql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start

运行brew info mysql ,并按照说明手动启动MySQL,或使用launchctl对其进行launchctl

您可以使用以下方法测试MySQL是否正在运行

mysql -uroot

另外,请确保使用正确的主机名,用户名和密码正确配置database.yml文件。 这些值取决于您(或自制)配置MySQL实例的方式。

如果您的终端出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ,那么您肯定有一个密码。 您可能已经忘记了。 另外,如果记得的话,转到config/database.yml文件并在其中填写您的mysql用户名和密码。

另外,如果您仍然没有密码, 使用brew remove mysql卸载, brew remove mysql然后尝试从oracle网站下载.dmg安装程序。

确保通过/etc/init.d/mysqld start启动了MySQL服务器。

mysql -u root产生您正在谈论的错误。 可以通过mysql -u root -p避免此错误(yup extra p有时可以解决您的问题)。

如果这不起作用,则可以尝试以下命令序列:

  1. sudo /etc/init.d/mysqld stop 停止MySQL服务器
  2. sudo /etc/init.d/mysqld restart 重新启动MySQL服务器
  3. ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 用于在实际的mysql.sock file/tmp/mysql.sock之间创建软链接
  4. /usr/bin/mysql_secure_installation 用于安全安装mysql。 即使已安装MySQL(用于故障排除),也可以运行此命令。 它将提示您输入root密码。 输入它,对于其他选项,只需键入n代表否。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM