The method of changing the default encoding of mysql to UTF8: first add [default-character-set=utf8] in the client field; then add [character-set-server=utf8] in the mysqld field; finally restart The mysql service takes effect.
Related learning recommendation: mysql tutorial
The method of changing the default encoding of mysql to UTF8 :
windows:
a. WIN+R net stop mysql close mysql service
b. Copy my -dafault.ini, renamed to my.ini, enter it
UBUNTU:
** sudo vim /etc/mysql/my.cnf **Enter
Perform the following operations:
1. In [client ] field, add default-character-set=utf8, 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 will take effect after restarting the mysql service. Note: There is a difference between the [mysqld] field and the [mysql] field. No one has reported this on the Internet.
Note: show variables like 'character%' can view the mysql encoding method, after the modification is completed, it looks 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/ | +--------------------------+---------------------- ------+
Want to learn more programming learning, please pay attention to the PHP training column!
The above is the detailed content of how to change the default encoding of mysql to UTF8. For more information, please pay attention to other related articles on 1024programmer.com!