Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make MySQL default to utf8mb4

Tags:

mysql

How does one make MySQL default to utf8mb4 for all strings, table types, and the connection encoding? I have this in my my.cnf file:

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
default-character-set=utf8mb4

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4

Yet I still have latin8 showing up in places.

like image 261
vy32 Avatar asked Nov 26 '25 22:11

vy32


1 Answers

Connection encoding can be overriden on per-session basis, and actually it is a good practice, so you need to check actual clients.

Keep eye on:

  • Databases and tables have their own encoding, you need to convert them.
  • in utf8mb4 maximum varchar length that fits in index is 191, not 255 as before, so transition is not just 'copy-paste-run'
  • backup dumps contain pre-transition encoding
  • some tools/migrations can contain old encoding
like image 166
Vasfed Avatar answered Nov 29 '25 20:11

Vasfed



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!