Squeryl utf8mb4 support

62 views Asked by At

I'm using Squeryl to work with a MySQL database. The tables are in utf8mb4 encoding. Now I want to insert some utf8 (4 byte) strings into the db through Squeryl. How do I do that?

I tried to set ?useUnicode=yes&characterEncoding=UTF-8 to my connection url but apparently, UTF-8 here is 3 byte to MySQL so it doesn't work.

I found this StackOverflow answer, but after some digging, I don't see anyway to append my queries with SET NAMES utf8mb4; (changing database config and environment is not an option)

Example string: อลิซร้องเพลงตามเลยค่ะ

Error when trying to insert the string:

Exception in thread "main" org.squeryl.SquerylSQLException: Exception while executing statement : Incorrect string value

1

There are 1 answers

0
Rick James On

Be sure not to connect as root.

Have this in my.cnf (in the [mysqld] section)

init_connect = SET NAMES utf8mb4