【发布时间】:2015-04-16 14:53:11
【问题描述】:
我有一台 Linux 机器(在 10.0.0.10 上),我部署了我的 Play 应用程序来使用它:
activator dist
我有一台运行 MySQL 的 Windows 机器(10.0.0.51)。
数据库设置了3个用户账号root@localhost、db_user@localhost、db_user@%所有用户都拥有所有权限(仅供测试)。
我可以使用mysql shell 从 Linux 机器访问数据库:
[neil@localhost ~]$ mysql -u db_user -p -h 10.0.0.51
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test_db |
| mysql |
| performance_schema |
| sakila |
| test |
| world |
+--------------------+
8 rows in set (0.04 sec)
mysql>
test_db 是我在 Windows 机器上设置的测试数据库。
但是,当我尝试运行 Play 应用程序时,我得到以下信息:
[neil@localhost ~]$ ~/TEST_APP-1.0-SNAPSHOT/bin/test_app
Play server process ID is 5908
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial
connection Sleeping for 0ms and trying again. Attempts left: 0.
Exception: java.net.ConnectException: Connection
refused.Message:Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database
[db_user]]
at play.api.Configuration$.play$api$Configuration$$configError
(Configuration.scala:94)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
...
这是我的 application.conf 中的数据库配置:
db.db_user.driver=com.mysql.jdbc.Driver
db.db_user.url="jdbc:mysql://10.0.0.51:3306/test_db?allowMultiQueries=true"
db.db_user.user=db_user
db.db_user.pass="password"
db.db_user.partitionCount=3
db.db_user.maxConnectionsPerPartition=20
db.db_user.minConnectionsPerPartition=5
db.db_user.acquireIncrement=5
值得注意的是,当我在 Windows 上以开发模式运行应用程序时,此配置有效。但是我不知道 Linux 机器上出了什么问题,而且我已经没有东西可以尝试了。 (请注意,我在关闭所有防火墙的情况下尝试了此操作并遇到了同样的问题)。
更新
在我使用的播放应用程序中:
public static final String DB_USER = "db_user";
...
JdbcTemplate jt = new JdbcTemplate(DB.getDataSource(DB_USER));
所以我不应该在 conf 中使用 db.default.etc... 吗?这不正确吗?
更新 2
我不知道我是怎么错过的,但是堆栈跟踪中还有一些其他的东西表明了问题(堆栈跟踪很长,所以我不想列出整个事情,也许我应该有):
Caused by: java.net.ConnectException: Connection refused
所以...服务器正在侦听端口 3306,在运行 netstat -an 的 Windows 服务器上产生:
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP [::]:3306 [::]:0 LISTENING
防火墙已关闭(我知道……只是为了测试)。
MySQL 正在接受来自 CLI 的连接。
不过,我刚刚有一个脑电波...... application.conf 是在 Windows 上生成的......我想知道我是否需要在配置文件上运行 dos2unix,这就是它找不到 @987654338 的原因@。
更新 3
没有:(
【问题讨论】:
-
尝试在整个配置中将
db.db_user替换为db.default。 -
我得到了基于
"db_user"的数据源,所以这应该不是问题吧?查看我的更新。
标签: mysql linux playframework playframework-2.3