The default encoding for MySQL databases is not utf-8.
After installing MySQL, start the service and log in, use the show variables command to view the default encoding of the MySQL database:
The character set of database and server, as shown in the figure above, uses latin1 encoding, and does not support Chinese, that is, garbled characters will appear when storing Chinese. The following is the process of modifying the command line to UTF-8 encoding to support Chinese.
(1) Close MySQL service
Copy Code code as follows:
(2) Modify the/ETC/MYSQL/MY.CNF (default installation path)
Copy Code code as follows:
After opening the MY.CNF, add the following two lines to [mysqld] within the file:
Copy Code code as follows:
Character_set_server=utf8
init_connect= ' SET NAMES UTF8 '
(as shown in the screenshot):
Save exit.
(3) Restart the MySQL service
Copy Code code as follows:
At this point, complete the modification of the default encoding, landing MySQL after the use of show variable like '%character% ' to obtain the output effect as follows:
Note
The details of the operation and output are as follows: