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

查看:168
本文介绍了在Play framework 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 framework 2.0中使用MySQL数据库所需的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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