简体   繁体   English

玩!框架 - 无法连接到数据库

[英]Play! framework - Cannot connect to database

this is the error I get when I'm trying to connect to my local postgresql db: 这是我在尝试连接到本地postgresql db时遇到的错误:

Cannot connect to database [default] 无法连接数据库[默认]

this is the database configuration. 这是数据库配置。 I'm convinced that there is not typo (fat finger error) : 我确信没有拼写错误(胖手指错误)

db.default.url="postgres://localhost:5432/myproject/"
db.default.user="postgres"
db.default.pass="mypassword"
db.default.driver="org.postgresql.Driver"
db.default.initSQL="SELECT 1" 

where is the problem? 问题出在哪儿? with pgAdmin I can connect easily 使用pgAdmin我可以轻松连接
ps PS
I'm using ubuntu. 我正在使用ubuntu。 I've noticed that in order to change to postgres user 我注意到为了改成postgres用户
I must use "su" , otherwise it fails changing the current user. 我必须使用“su” ,否则它无法更改当前用户。
is that has something to do with play! 这与游戏有关! failure to connect my db? 无法连接我的数据库?

thanks 谢谢

There might be two things wrong or at least dubious in your setup. 您的设置中可能存在两个错误或至少可疑的问题。

First: The postgres:... URL syntax is not a plain JDBC URL. 第一: postgres:... URL语法不是普通的JDBC URL。 This format is not understood by the PostgreSQL JDBC driver. PostgreSQL JDBC驱动程序无法理解此格式。 See this answer to a similar problem. 看到类似问题的答案

Second: You are trying to use the PostgreSQL superuser account for Play. 第二:您正在尝试使用PostgreSQL超级用户帐户进行播放。 The superuser account should be used only for administrative work, but not "normal" work. 超级用户帐户应用于管理工作,而不能用于“正常”工作。 Especially not for work which includes public access to the DB via some webfrontend. 特别是对于通过某些webfrontend包含对DB的公共访问的工作。 Any SQL-Injection attack gives the attacker the golden key to your database - including the nuke to wreck your complete DB cluster at once or install any backdoor into you DB server. 任何SQL注入攻击都会为攻击者提供数据库的金钥匙 - 包括一次性破坏整个数据库集群或将任何后门安装到数据库服务器中的核心攻击。

So I recommand, that you create a new user which you configure in your Play! 所以我建议您创建一个在Play中配置的新用户! settings. 设置。

That said: The default password for the postgres user is not set on Ubuntu. 也就是说:在Ubuntu上没有设置postgres用户的默认密码。 This setup allows login to the DB user only from the same OS user . 此设置允许仅从同一OS用户登录DB 用户 How you can fix this is explained in this answer . 如何解决这个问题在这个答案中解释。

If these two tips don't help: The error you quoted is very vague. 如果这两个提示没有帮助:您引用的错误非常模糊。 There must be more detailed error logs somewhere . 某处 必须有更详细的错误日志。 Please find them and attach them to your question with the "edit" button. 请找到它们并使用“编辑”按钮将它们附加到您的问题中。

This is not an answer directly to your question, but I had the same error message and came here via Google. 这不是您的问题的直接答案,但我有相同的错误消息,并通过谷歌来到这里。 Using Scala Play 2.3, I had 使用Scala Play 2.3,我有

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true

which needed to be 这需要

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true

I accidentally left the quotes around the driver name out. 我不小心把驱动器名称的引号留了下来。 Now it works perfectly. 现在它完美无缺。

here is my conf, it works: 这是我的conf,它有效:

db.default.url="jdbc:postgresql://127.0.0.1:5432/dbname"
db.default.driver="org.postgresql.Driver"

just add the jdbc: before postgresql in db.default.url . 只需在db.default.url postgresql之前添加jdbc: db.default.url

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

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