1, Log in to MySQL to view SHOW VARIABLES LIKE 'character%'; the following character set is displayed as follows:
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+character_set_database and character_ set_ The default character set of the server is still latin1.
2, The simplest and perfect way to modify mysql my.cnf Character set key value in the file (pay attention to the configured field details):
First look at your my.cnf Where is the file? On Linux, enter the find / -iname '*.cnf' -print command to find it my.cnf File, and then modify it as shown below.
1,stay[client]Add to field default-character-set=utf8,As follows: [client] port = 3306 socket = /var/lib/mysql/mysql.sock default-character-set=utf8 2,stay[mysqld]Add to field character-set-server=utf8,As follows: [mysqld] port = 3306 socket = /var/lib/mysql/mysql.sock character-set-server=utf8 3,stay[mysql]Add to field default-character-set=utf8,As follows: [mysql] no-auto-rehash default-character-set=utf8
After the modification, service mysql restart will take effect after restarting mysql service. Note: there is a difference between the [mysqld] field and the [mysql] field. There is no feedback on this on the Internet.
Use SHOW VARIABLES LIKE 'character%'; check and find that the database code has been changed to utf8.
+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+