Set UTF-8 encoding for MySQL5.7 in Ubuntu 16.04

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!

Ready to work##

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

Add settings##

Configure the mysqld.cnf file###

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

Configure the mysql.cnf file###

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

View configuration results##

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

Set UTF-8 encoding for MySQL5.7 in Ubuntu 16.04
How to install mysql in Ubuntu 14.04
Installation instructions for gitlab in Ubuntu
How to install mysql in Ubuntu 14.04
How to set static IP in ubuntu14.04
Set static IP for CentOS in VMware
Graphical tutorial for installing Pycharm 2020.1 in Ubuntu 20.04
Eclipse does not support gbk encoding in ubuntu
Remotely connect to MySQL database in Ubuntu environment
Ubuntu14 upgrade MySQL
Some tips for viewing kernel repair information in ubuntu
How to set up Ghost one-click app for Ubuntu 16.04
Installation and simple practice of MySQL in ubuntu environment (1)
Tutorial for setting up FTP server in Ubuntu 16.04 environment
Many attempts to set up soft routing in ubuntu
Manual for Ubuntu Installation
Install mysql-pytho in Ubuntu
ubuntu 17.10 set solid IP
Install MySQL5.7 in centos7
Install mysql under Ubuntu 16.04
Use supervisor in ubuntu
Install mysql on Ubuntu 14.04
Ubuntu19 install MySQL pit
Ubuntu completely remove MySQL
Install python in Ubuntu
Install JDK in Ubuntu19.10
Install MySQL under Ubuntu
ubuntu16.04 set static ip
ubuntu set Chinese font
Interesting applications that can be used for teaching in ubuntu16.04
How to set up vsftpd for anonymous downloads on Ubuntu 16.04
Detailed steps to automatically set the line number in ubuntu16.04
Detailed steps for installing Django under Python 3.6 in Ubuntu 16.04 environment
How to set up vsftpd for user directories on Ubuntu 16.04