1

I have a Linux machine (on 10.0.0.10) which I deployed my Play app to using:

activator dist

I have a Windows machine (on 10.0.0.51) running MySQL.

The database has 3 user accounts set up root@localhost, db_user@localhost, db_user@% all users have all permissions (it's just for testing).

I can access the db from the Linux machine using the mysql shell:

[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>

Where test_db is the test database I set up on the Windows machine.

However when I try to run the Play application I get the following:

[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.

...

Here is the db config in my 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

It is worth noting that this configuration works when I am running the app in dev mode on Windows. But I do not know what's wrong on the Linux box and I have run out of things to try. (note I tried this with all firewalls turned off and got the same issue).

UPDATE

Within the play application I use:

public static final String DB_USER = "db_user";

...

JdbcTemplate jt = new JdbcTemplate(DB.getDataSource(DB_USER));

So I shouldn't have to use db.default.etc... in the conf? Is this not correct?

UPDATE 2

I don't know how I missed this but there was something else further down in the stack trace that is indicative of the problem (the stack trace is quite long so I didn't want to list the whole thing, maybe I should have):

Caused by: java.net.ConnectException: Connection refused

So... the server is listening on port 3306, on the windows server running netstat -an yields:

TCP    0.0.0.0:3306     0.0.0.0:0     LISTENING
TCP    [::]:3306        [::]:0        LISTENING

The firewall is turned off (I know... just for testing).

And MySQL is accepting connections from the CLI.

I've just had a brain wave though.... The application.conf was generated on windows... I wonder if I need to run dos2unix on the config file which would be why it cannot find "db_user".

UPDATE 3

No :(

Neilos
  • 2,696
  • 4
  • 25
  • 51

2 Answers2

1

You need to use db.default in conf. from JavaDatabase

Community
  • 1
  • 1
  • Member for 4 days and already giving answers... goooooood! You should link the docs' latest version though. – sebster Apr 16 '15 at 16:48
1

I think the correct key to specify the password is not pass, but password:

db.db_user.password="password"

Also you can try to use db.default.* and DB.getDataSource(), but I guess that will not make much difference...

Salem
  • 12,808
  • 4
  • 34
  • 54
  • Interesting... it would seem that you are right, but this never stopped it working before (when I ran both the db and the server locally on windows). Alas, it didn't fix the issue, I think that my issue is that my Play server cannot even see the database (`java.net.ConnectException: Connection refused`) but I'm completely bamboozled as to why; I can connect from the command line. – Neilos Apr 16 '15 at 23:01
  • BTW db_user in `db.db_user.user=db_user` should be quoted. Try to add `logger.com.jolbox=DEBUG` to your `application.conf` to see if you get more information in the console – Salem Apr 16 '15 at 23:12
  • I added that config option but it had no effect, also I don't see that the username needs to be in quotes from the docs https://www.playframework.com/documentation/2.3.x/SettingsJDBC but I tried both and no change – Neilos Apr 16 '15 at 23:25
  • @Neilos Did you get to solve this? I am stuck in kind of similar issue where I am not able to access my mysql database installed on a separate public cloud from my app deployed on another public cloud. I am able to access the database from the mysql workbench, but the application is somehow not able to see it. Please share any of your observations you used to resolve this might help! – user1242321 Oct 05 '15 at 07:47
  • @user1242321 I'm assuming that this is the related question http://stackoverflow.com/questions/32946111/jdbc-connection-to-remote-mysql-db-fails I'll try to help in there, but to be honest I didn't find a solution, I am still in development and I am now just running the App and Mysql on the same local machine. I have since upgraded to play 2.4 and not tested it for the same issue. I might tonight try to do it again to see if I still have the same issues. It was a peculiar problem. – Neilos Oct 05 '15 at 18:36
  • @Neilos yes buddy. :) I added that question yesterday when I could not find a solution. Do let me know if you find any solution to this and I will also update the question if I get past it. Thanks. – user1242321 Oct 05 '15 at 18:40
  • 1
    @user1242321 I just installed a VM with Mysql using my local machine as the play server (Play 2.4) (this was the issue I was having before) and it works now. so I don't have any issues, all I'd say is make sure that your user has access allowed from your server, try what I use for example: `GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;` however that is just for dev I will refine privileges for production! – Neilos Oct 06 '15 at 01:28