Change MySQL default character set to UTF-8 in my.cnf?

前端 未结 18 953
一个人的身影
一个人的身影 2020-11-22 01:55

Currently we are using the following commands in PHP to set the character set to UTF-8 in our application.

Since this is a bit of overhead, we\'d like to set this a

18条回答
  •  难免孤独
    2020-11-22 02:19

    MySQL versions and Linux distributions may matter when making configurations.

    However, the changes under [mysqld] section is encouraged.

    I want to give a short explanation of tomazzlender's answer:

    [mysqld] 
    init_connect='SET collation_connection = utf8_unicode_ci' 
    init_connect='SET NAMES utf8' 
    character-set-server=utf8 
    collation-server=utf8_unicode_ci 
    skip-character-set-client-handshake
    

    [mysqld]

    This will change collation_connection to utf8_unicode_ci

    init_connect='SET collation_connection = utf8_unicode_ci'
    

    Using SET NAMES:

    init_connect='SET NAMES utf8'
    

    The SET NAMES will influence three characters, that is:

    character_set_client
    character_set_results
    character_set_connection
    

    This will set character_set_database & character_set_server

    character-set-server=utf8
    

    This will only affect collation_database & collation_server

    collation-server=utf8_unicode_ci
    

    Sorry, I'm not so sure what is this for. I don't use it however:

    skip-character-set-client-handshake
    

提交回复
热议问题