Keycloak on MySQL 8 with utf8mb4

1,067 views
Skip to first unread message

benjam...@gmail.com

unread,
Jan 13, 2022, 11:41:39 AM1/13/22
to Keycloak User
In the latest documentation (16.1.0) [1] under "MySQL database" section, it is still giving the example of MySQL 5.5 as why utf8 (utf8mb3) character set should be used as default and utf8mb4 would not work for Keycloak due to "different storage requirement". Rolling forward now to MySQL 8, are there any new guidances on whether utf8mb4 can work with Keycloak?

I did a test-run of a vanilla Keycloak 16.1.0 over a MySQL schema with utf8mb4/utf8mb4_unicode_ci, the tables were created. All tables inherited the utf8mb4/utf8mb4_unicode_ci from the schema, except for 18 columns that remain explicitly utf8/utf8_general_ci. The service appeared to be starting up fine.

I also have a Keycloak database that was created in MySQL 5.x and utf8 but has since been upgraded to MySQL 8. I have run a script to convert all tables and columns from utf8 to utf8mb4. Keycloak appears to be running fine so far. 

Does anyone else have success or issues with Keycloak on MySQL 8 utf8mb4, especially during upgrades? And should the official documentation/guidance be updated to reflect the use of utf8mb4 if the "different storage requirement" in the documentation might no longer be an issue in MySQL 8?

On a side note, MySQL has said that utf8 will become alias to utf8mb3 in upcoming 8.0.28 but is "expected subsequently to become a reference to utf8mb4" [2]. Not sure if that has any impact on new Keycloak databases in some distant future if some columns are fixed to utf8


benjam...@gmail.com

unread,
May 31, 2022, 7:54:41 AM5/31/22
to Keycloak User
Just to follow up on my last post from 13 January, in case anyone else has the same query.

We have since tested utf8mb4/utf8mb4_unicode_ci on the Keycloak schema on MySQL 8.0.27 for a few months and have encountered no problem. This included creating fresh instance and upgrading existing ones from 16.1.0 to 18.0.0.  The official documentation/guidance as of 18.0.0 [1] has remained unchanged, that it still references MySQL 5.x and that utf8 is preferred over utf8mb4. The referenced issue in the documentation - KEYCLOAK-3873 [2] - appears to to be not an issue when running in MySQL 8.

Suggest updating the official document [1] regarding MySQL 8 and utf8mb4 unless there is something that we have missed.

Hope this helps anyone.

[1] https://www.keycloak.org/docs/latest/server_installation/#unicode-considerations-for-databases
[2] https://issues.redhat.com/browse/KEYCLOAK-3873
Reply all
Reply to author
Forward
0 new messages