Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Incorrect string value" errors with MySQL even with utf8mb4_unicode_ci

My database stores server hostnames of Garry's Mod servers (Source Dedicated Servers) and sometimes they seem to contain characters that utf8mb4_unicode_ci can't store. What are these characters and how do I fix the issue?

insert into `servers` (`steamid64`, `script_id`, `ip_address`, `port`, `uses`, `hostname`, `maxplayers`, `map`, `last_active`) values (XXXXXXXXXXXXXXX, 1599, XXXXXXXXXXX, 27095, 1, [FR] USA vs F?d?ration | Apocalypse | SeriousRP | TSF, 20, rp_evocity_dc, CURRENT_TIMESTAMP())

Incorrect string value: '\xE9d\xE9rat...'

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9d\xE9rat...' for column 'hostname' at row 1 (SQL: insert into `servers` (`steamid64`, `script_id`, `ip_address`, `port`, `uses`, `hostname`, `maxplayers`, `map`, `last_active`) values (XXXXXXXXXXXXXXX, 1599, XXXXXXXXXXXXXXXX, 27095, 1, [FR] USA vs F?d?ration | Apocalypse | SeriousRP | TSF, 20, rp_evocity_dc, CURRENT_TIMESTAMP()))
  File "app/Http/Controllers/PayloadController.php", line 243, in GetPayload
    $Server -> save();
  File "public/index.php", line 55
    $request = Illuminate\Http\Request::capture()
like image 590
Billy Avatar asked Feb 23 '26 05:02

Billy


1 Answers

You were hoping for ...édérat... ?

Your client is using latin1, not utf8mb4.

Perhaps the simplest fix is to tell mysql that you are using latin1 in the client. This is best done in the connection string. (Are you using PDO or mysqli?)

Note: The encoding of the client and the encoding in the database table are independent. The transcoding is automatic. But you must be correct in declaring the encoding in the client.

like image 75
Rick James Avatar answered Feb 24 '26 19:02

Rick James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!