Backend for the persistent library using MySQL database server.

Version on this page:2.9.0@rev:1
LTS Haskell 22.30:
Stackage Nightly 2024-07-23:
Latest on Hackage:

See all snapshots persistent-mysql appears in

MIT licensed by Felipe Lessa, Michael Snoyman
Maintained by Felipe Lessa
This version can be pinned in stack with:persistent-mysql-2.9.0@sha256:7fc3898b44d2e4a43a9db36cab864b60583def67401a37cef54a2ad211d07177,2045

Module documentation for 2.9.0

This package contains a backend for persistent using the MySQL database server. Internally it uses the mysql-simple and mysql packages in order to access the database.

This package supports only MySQL 5.1 and above. However, it has been tested only on MySQL 5.5. Only the InnoDB storage engine is officially supported.

Known problems:

  • This package does not support statements inside other statements.


Changelog for persistent-mysql


  • Added support for SQL isolation levels to via SqlBackend. [#812]
  • Fix 832: repsertMany now matches mapM_ (uncurry repsert) and is atomic.


  • Implemented connPutManySql to utilize batched putMany. #770


  • Switch from MonadBaseControl to MonadUnliftIO
  • Fix duplicate migrations when using mediumtext, longtext, mediumblob, longblob, and doubles using a custom precision. #754

– This can be released as a minor change on the next update. Currently persistent-mysql can’t be released because depends on persistent-2.7.2 being released.

  • The SomeField type was renamed to HandleUpdateCollision and deprecated. Please migrate to using HandleUpdateCollision.
  • The SomeField constructor was deprecated, and a temporary pattern synonym introduced. Please migrate to using copyField. [UNRELEASED ON HACKAGE]

– This version depends on persistent 2.7.2, which introduced breaking changes and is deprecated on hackage.

  • Fix ambiguous type errors introduced by persistent-2.7.2 #723

  • Fix haddock documentation #725


  • Extend the SomeField type to allow insertManyOnDuplicateKeyUpdate to conditionally copy values.
  • Depend on mysql-simple >= 0.4.3 to fix encoding and decoding of date/time values with fractional seconds (when a column is specified using something like sqltype=TIME(6)). See also #705
  • Fix behavior of insertManyOnDuplicateKeyUpdate to ignore duplicate key exceptions when no updates specified.


  • Add functions insertOnDuplicateKeyUpdate, insertManyOnDuplicateKeyUpdate to Database.Persist.MySQL module.

Prevent spurious no-op migrations when default=NULL is specified - revised version #672 (which fixes bug #671 introduced by the earlier attempt #641)


Compatibility for backend-specific upsert functionality. A lucky contributor could add upsert to the MySQL backend now, i.e.: INSERT … ON DUPICATE …


  • changes for read/write typeclass split

Support usign default= for changing the id field type


  • Distinguish between binary and non-binary strings in MySQL #451
    • Previously all string columns (VARCHAR, TEXT, etc.) were being returned from Persistent as PersistByteStrings (i.e. as binary data). Persistent now checks character set information to determine if the value should be returned as PersistText or PersistByteString.
    • This is a breaking change if your code is relying on a PersistByteString being returned for string-like MySQL values; persistent-mysql itself had several runtime errors that needed to be fixed because of this patch. High-level code dealing purely with PersistEntities should be unaffected.


  • Update to persistent 2.2


  • Added a Show instance for MySQLConf.

Documentation typo fix


Provide a FromJSON instance for MySQLConf.