使用spring boot的mysql的hikari配置

dxpyg8gm  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(452)

我有一个使用mysql数据库的spring启动应用程序。我正在使用hikari连接池。
根据hikari的官方博客https://github.com/brettwooldridge/hikaricp/wiki/mysql-configuration,我必须设置一些属性以提高性能。

dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048
dataSource.useServerPrepStmts=true
dataSource.useLocalSessionState=true

但我不知道如何在不显式创建hikaridatasource的bean的情况下设置这些属性,如本文所述:https://github.com/brettwooldridge/hikaricp/issues/1200
我渴望通过spring配置文件(property文件或yml文件)直接设置这些属性

iezvtpos

iezvtpos1#

可以通过简单的配置轻松配置这些参数。
只需在标准spring数据源->url属性中附加这些属性

spring.datasource.url=jdbc:mysql://localhost:3306/databasename?rewriteBatchedStatements=true&useLocalSessionState=true&cachePrepStmts=true&prepStmtCacheSize=250&prepStmtCacheSqlLimit=2048

类似地,可以使用&symbol附加其他属性。

相关问题