简体   繁体   English

用户拒绝Rails乘客和mysql访问

[英]Rails Passenger & mysql Access denied for user

I have a rails application running on Fedora 20 against Apache & mysql (Maria db) It worked with no issues until a recent update to Fedora , afterwards passanger failed with this error 我有一个针对Apache和mysql(Maria db)的Fedora 20上运行的Rails应用程序,直到最近对Fedora进行了更新,它都没有问题,之后passanger失败了,并显示此错误

Web application could not be started Web应用程序无法启动

Access denied for user 'user'@'localhost' to database 'TheDB' (Mysql2::Error) 用户'user'@'localhost'对数据库'TheDB'的访问被拒绝(Mysql2 :: Error)

running rails from the command line using WEBrick works fine, it is also possible to connect to the mysql with 使用WEBrick从命令行运行rails效果很好,也可以使用以下命令连接到mysql

mysql -u user -h loalhost m -p mysql -u用户-h loalhost m -p

reinstalling passenger & mysql2 gem did not help 重新安装passenger&mysql2 gem没有帮助

After a few hours of tackling this I am drawing a complete blank on what else to try 解决了几个小时后,我在尝试其他方法时完全空白了

I will welcome any ideas 我欢迎任何想法

If you can connect using the right username and password from command line but your scripts cannot connect using the same credentials, check the the database mysql, table user for the correct values in the column Host. 如果可以从命令行使用正确的用户名和密码进行连接,但是脚本无法使用相同的凭据进行连接,请在“主机”列中的数据库mysql表用户中检查正确的值。

SELECT Host FROM mysql.user WHERE User='myusername';

From http://dev.mysql.com/doc/refman/5.1/en/connection-access.html : http://dev.mysql.com/doc/refman/5.1/en/connection-access.html

Identity checking is performed using the three user table scope columns ( Host , User, and Password). 使用三个用户表作用域列( 主机 ,用户和密码)执行身份检查。 The server accepts the connection only if the Host and User columns in some user table row match the client host name and user name and the client supplies the password specified in that row. 仅当某些用户表行中的“ 主机”和“ 用户”列与客户端主机名用户名匹配,并且客户端提供该行中指定的密码时,服务器才接受连接。

Check if the sorting rules are not affecting you : 检查排序规则是否不影响您:

The server uses the first row that matches the client host name and user name . 服务器使用与客户端主机名和用户名匹配的第一行

I faced the exact same issue. 我面临着完全相同的问题。 while setting up the ror app all the rake commands worked fine. 在设置ror应用程序时,所有rake命令都可以正常工作。 mysql was simply accessible from linux console by simply typing "mysql" and it take to mysql console and database.yml was using root user with empty password. 只需输入“ mysql”,即可从linux控制台轻松访问mysql,并将其带到mysql控制台和database.yml使用具有空密码的root用户。

Exact same setup was working on other dev instances but after spending a full day i got the solution. 完全相同的设置正在其他开发人员实例上运行,但是花了一整天后,我得到了解决方案。

When we use following configs in database.yml 当我们在database.yml中使用以下配置时

*evelopment: &development
  adapter: mysql2
  database: development
  encoding: utf8
  username: root
  password:
  host: localhost
  socket: /var/run/mysqld/mysqld.sock*

Then application tries to connect to mysql as "mysql -u root -h localhost" and in my case this command was giving following error. 然后应用程序尝试以“ mysql -u root -h localhost”连接到mysql,在我的情况下,该命令给出以下错误。

*$mysql -u root -h 127.0.0.1
ERROR 1698 (28000): Access denied for user 'root'@'localhost'*

After adjusting root user with following, issue resolved. 用以下命令调整根用户后,问题已解决。

*sudo mysql -u root
use mysql;
update user set plugin='' where User='root';
flush privileges;
exit;*

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

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