Search code examples
mysqlscalaplayframeworkoauth-2.0playframework-2.3

Play scala - oauth2 provider mysql issue


AIM:

I am trying to implement the oauth2 in my application using Play framework 2.3, scala language and MySQL.

WHAT I DID:

I tried to use the scala-oauth2-provider. The given sample is working fine with PostgreSQL. But I want to implement this with MySQL.

WHAT I TRIED:

I have added the below dependencies in the build.sbt

"mysql"       % "mysql-connector-java" % "5.1.18",
jdbc

and I removed the below dependency in the given sample.

  "org.postgresql" % "postgresql" % "9.3-1100-jdbc41"

Changed the DB configuration in the application.conf

#db.default.url="jdbc:mysql://localhost/oauth"
db.default.url="jdbc:mysql://localhost:3306/oauth"  
db.default.driver="com.mysql.jdbc.Driver"
db.default.user="root"
db.default.pass="root"
db.default.host="localhost"

ISSUE:

I am facing the below issue.

[error] - c.j.b.h.AbstractConnectionHook - 14:16:25.117 - Caller+0   at com.jolbox.bonecp.hooks.AbstractConnectionHook.onAcquireFail(AbstractConnectionHook.java:77)
 - Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: null.Message:Access denied for user 'root'@'localhost' (using password: YES)
[error] - application - 14:16:25.131 - Caller+0  at play.api.LoggerLike$class.error(Logger.scala:141)
 - 

! @6nmjm0p14 - Internal server error, for (GET) [/] ->

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.11-2.3.4.jar:2.3.4]
    at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.11-2.3.4.jar:2.3.4]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.11-2.3.4.jar:2.3.4]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.11-2.3.4.jar:2.3.4]
    at scala.collection.immutable.List.map(List.scala:273) ~[scala-library-2.11.6.jar:na]
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) ~[mysql-connector-java-5.1.18.jar:na]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) ~[mysql-connector-java-5.1.18.jar:na]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) ~[mysql-connector-java-5.1.18.jar:na]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943) ~[mysql-connector-java-5.1.18.jar:na]
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113) ~[mysql-connector-java-5.1.18.jar:na]

I have given the correct mysql credential only and also I have the database named oauth. Even though it throws "Access denied for user 'root'@'localhost' (using password: YES)" error.

Can anyone help me to fix this?


Solution

  • Please take the following actions:

    1. In mysql, under root user:

      CREATE USER 'test1'@'localhost' IDENTIFIED BY 'mypass';
      CREATE DATABASE oauth;
      GRANT ALL ON oauth.* TO 'test1'@'localhost';
      
    2. Change credentials in your conf/application.conf:

      db.default.user="test1"
      db.default.pass="mypass"
      

    Then run your application. This should work.