在 Play 框架 2.0 中使用 MySQL 数据库所需的步骤 [英] Steps needed to use MySQL database with Play framework 2.0

查看:30
本文介绍了在 Play 框架 2.0 中使用 MySQL 数据库所需的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Play 框架的新手.我正在尝试将 MySQL 数据库配置为与 Play Ebeans 一起使用的数据源.

I'm new to Play framework. I'm trying to configure MySQL database as a datasource to be used with Play Ebeans.

能否请您解释一下使用 Play 2.0 框架配置 MySQL 所需的步骤(例如,下载驱动程序、添加依赖项等).

Could you some one please explain the steps that are needed to configure MySQL with Play 2.0 framework (like, downloading drivers, adding dependency etc).

推荐答案

这个页面 来自 Play 的文档.它说:

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

除了 h2 内存数据库,主要用于开发模式,Play 2.0 不提供任何数据库驱动程序.因此,要在生产中进行部署,您必须将数据库驱动程序添加为应用程序依赖项.

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.

例如,如果你使用MySQL5,则需要为连接器添加一个依赖:

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 将为您下载驱动程序.您还应该查看关于管理依赖项的部分.

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

要连接到 MySQL,您还需要更改 application.conf 中的一些设置:

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

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

这篇关于在 Play 框架 2.0 中使用 MySQL 数据库所需的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆