How to change the default encoding of mysql to UTF8: first add [default-character-set=utf8] to the client field; then add [character-set-server=utf8] to the mysqld field; finally restart The mysql service will take effect.
Related learning recommendations: mysql tutorial
Change the default encoding of mysql Method for UTF8:
windows:
a. WIN R net stop mysql Close the mysql service
b. Copy my-dafault .ini, rename it to my.ini, enter it
UBUNTU:
** sudo vim /etc/mysql/my.cnf **进入
Perform the following operations:
1. Add default-character-set=utf8 in the [client] field, as follows:
[client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8
2. Add character-set-server=utf8 in the [mysqld] field, as follows:
[mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock character-set-server=utf8
3. Add default-character-set=utf8 in the [mysql] field, as follows:
[mysql] no-auto-rehash default-character-set=utf8
After the modification is completed, service mysql restart restarts the mysql service to take effect. Note: There is a difference between the [mysqld] field and the [mysql] field. No one has reported this online.
Note: show variables like 'character%' can view the mysql encoding method. After the modification is completed, it will look like this:
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
If you want to know more about programming learning, please pay attention to the php training column!
The above is the detailed content of How to change mysql default encoding to UTF8. For more information, please follow other related articles on the PHP Chinese website!