Steps needed to use MySQL database with Play framework 2.0 Steps needed to use MySQL database with Play framework 2.0 java java

Steps needed to use MySQL database with Play framework 2.0


Look at this page from Play's documentation. It says:

Other than for the h2 in-memory database, useful mostly in development mode, Play 2.0 does not provide any database drivers. Consequently, to deploy in production you will have to add your database driver as an application dependency.

For example, if you use MySQL5, you need to add a dependency for the connector:

val appDependencies = Seq(    // Add your project dependencies here,    ...    "mysql" % "mysql-connector-java" % "5.1.18"    ...)

SBT will download the driver for you. You should also check out the section on managing dependencies.

To connect to MySQL, you will also need to change some settings in your application.conf:

db.default.driver=com.mysql.jdbc.Driverdb.default.url="mysql://root:secret@localhost/myDatabase"


As Carsten wrote it can be fetched from documentation, however here's a summary:

make sure you have the dependency configured in /project/Build.scala

val appDependencies = Seq(    // Add your project dependencies here,    "mysql" % "mysql-connector-java" % "5.1.18")

Add a proper config of the DB (replace default H2 config) in /conf/application.conf:

(don't remove encoding from URL):

db.default.driver=com.mysql.jdbc.Driverdb.default.url="jdbc:mysql://localhost/your_db_name?characterEncoding=UTF-8"db.default.user=your_logindb.default.password=your_pass

in the same file find and make sure this line is NOT commented:

ebean.default="models.*"

That's all, restart your app (or run in dev mode), then it will create a DDL and ask you to apply it.


I am using play 2.2.0 and I just had to add the following line to build.sbt in project's root folder.

  "mysql" % "mysql-connector-java" % "5.1.27"

And play automatically downloads the driver. It seems Build.scala is not needed for this anymore. Changes to application.conf should be applied as the above commentators have mentioned.