MySQL Configuration

Brett Wooldridge edited this page May 11, 2018 · 9 revisions

In order to get the best performance out of MySQL, these are some of our recommended settings. There are many other performance related settings available in MySQL and we recommend reviewing them all to ensure you are getting the best performance for your application.

prepStmtCacheSize
This sets the number of prepared statements that the MySQL driver will cache per connection. The default is a conservative 25. We recommend setting this to between 250-500.

prepStmtCacheSqlLimit
This is the maximum length of a prepared SQL statement that the driver will cache. The MySQL default is 256. In our experience, especially with ORM frameworks like Hibernate, this default is well below the threshold of generated statement lengths. Our recommended setting is 2048.

cachePrepStmts
Neither of the above parameters have any effect if the cache is in fact disabled, as it is by default. You must set this parameter to true.

useServerPrepStmts : Newer versions of MySQL support server-side prepared statements, this can provide a substantial performance boost. Set this property to true.

A typical MySQL configuration for HikariCP might look something like this:

jdbcUrl=jdbc:mysql://localhost:3306/simpsons
user=test
password=test
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048
dataSource.useServerPrepStmts=true
dataSource.useLocalSessionState=true
dataSource.rewriteBatchedStatements=true
dataSource.cacheResultSetMetadata=true
dataSource.cacheServerConfiguration=true
dataSource.elideSetAutoCommits=true
dataSource.maintainTimeStats=false

See Also

If you are using MySQL, you really need to read this slide-stack

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.