0

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

Minh Thai
  • 568
  • 6
  • 18
  • Is there a `charset=utf8mb4` argument in addition to `?useUnicode=yes&characterEncoding=UTF-8`? – Rick James Apr 15 '18 at 01:09
  • Sadly no according to [MySQL documentation](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html) about Configuration Properties (see at the bottom) – Minh Thai Apr 15 '18 at 07:27
  • And you can't execute `SET NAMES utf8mb4` right after connecting? – Rick James Apr 16 '18 at 01:49

1 Answers1

0

Be sure not to connect as root.

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

init_connect = SET NAMES utf8mb4
Rick James
  • 135,179
  • 13
  • 127
  • 222