Home >Database >Mysql Tutorial >MySQL method and precautions to change the default character set to utf-8 through my.cnf_MySQL
Option configuration
Configuration file path: /full/path/mysql/bin/my.cnf
(default is /etc/my.cnf
)
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [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
*Note:
If you use the default-character-set setting in mysqld, mysql will report an error when starting and cannot start.
Instructions
Regarding the utf8 character set, our domestic default choice is: utf8_general_ci
instead of utf8_unicode_ci
,
The difference lies in the character comparison
Please see the example above mysql:
For general, ß = s is true
But for unicode, ß = ss is true,
In fact, the difference between them is mainly in German and French, so for us Chinese, we generally use general because general is faster
If you have higher requirements for the comparison between German and French, use unicode. It is more accurate than general (according to German and French standards, it is more accurate in comparison or sorting)
Check out this document: http://dev.mysql.com/doc/refman/5.7/en/charset-unicode-sets.html
In addition, utf8_bin_ci is also commonly used. When comparing characters, neither unicode nor general is case sensitive, so if case sensitivity is required, use bin
Summary
The above is the entire content of this article. I hope it will be helpful to everyone’s study or work. If you have any questions, you can leave a message to communicate.