I encountered a weird problem today, er, uncomfortable, when I used mysql to create a table, I just entered Chinese and reported an error. Later, I looked at the encoding format of mysql and surprised me. I have never used a format: The format of latin1 is a bit dizzy. Later, the query found that it is the default encoding format in mysql, but isn't the current encoding cleared of utf-8? Why is this, hey, now because the front and back end encodings are all in utf-8 format, I have no choice but to modify the mysql default encoding format. A tutorial is attached to everyone, I hope it can help you!
You have to prepare in advance for everything, first see if this is the case on your website! First use the command line to enter MySQL, and then execute the following commands:
View coding commands:
SHOW VARIABLES LIKE 'character%';
mysql> show variables like 'character%';+--------------------------+----------------------------+| 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/|+--------------------------+----------------------------+8 rows inset(0.00 sec)
At first glance, character_set_database
and character_set_server
are both layin1, which is a bit uncomfortable, do it yourself!
**For Ubuntu 16.04 version, the location for installing mysql by yourself is generally at: **
/etc/mysql
Find the /etc/mysql/mysql.conf.d/mysqld.cnf
file, and add the character-set-server=utf8
statement after the lc-messages-dir = /usr/share/mysql
statement
Find the /etc/mysql/conf.d/mysql.cnf
command to open the mysql.cnf
configuration file and add the code: default-character-set=utf8
as shown in the figure:
After the configuration is complete, restart mysql to see if the restart can be successful. Remember that no information output is the best information.
Command: systemctl restart mysql
Okay, log in to the MySQL terminal again to see if it's changed?
command:
show variables like 'character%';
mysql> SHOW VARIABLES LIKE 'char%';+--------------------------+----------------------------+| 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/|+--------------------------+----------------------------+8 rows inset(0.00 sec)
Okay, there is no problem. Have you solved it? If you have any questions, come to me in the comment section!
Link to this article: https://www.debuginn.cn/2251.html
This article is licensed under the [CC BY-NC-SA 3.0 Unported] (https://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh) agreement, please keep the link to this article for reprinting
Recommended Posts