Configure the character encoding for MySQL under Ubuntu. After installing MySQL, the system default character encoding is latin1, the input is Chinese, but the output is a bunch of garbled. Now all we have to do is set MySQL's default character encoding to support Chinese encoding, such as GBK, GB23112, and so on.
First enter the directory where MySQL stores the configuration files
~ #cd /etc/mysql/
Execute ls to view the files under this folder
~ #ls
Will find a file that is my.cnf, this file is a MySQL configuration file
Open this file with vim
~ #vi MY.CNF
After opening my.cnf, you will find two lines at the end of this file (this configuration file also references the other two profiles, we need to modify the MYSQLD.CNF, this is the MySQL server base configuration file):
!INCLUDEDIR/ETC/MYSQL/CONF.D !INCLUDEDIR/ETC/MYSQL/MYSQL.CONF.D
Open the/etc/mysql/mysql.conf.d/mysqld.cnf file with vim (if the prompt is not editable, you can switch the account to root)
~ #vi/etc/mysql/mysql.conf.d/mysqld.cnf
After opening the file, under [Mysqld] skip-external-locking, add the Character-set-server=utf8
...... [Mysqld] ...... skip-external-locking Character-set-server=utf8 ...
Below, we also go to set the client's default encoding, we now enter the MySQL client configuration file directory
~ #cd/etc/mysql/conf.d ~ #ls
LS, we found a file mysql.cnf
Open with VI and insert a line under [MySQL]: Default-character-set=utf8
~ #vi mysql.cnf [MySQL] Default-character-set=utf8
Finally, restart the MySQL service
~ #service mysql Restart
Go to MySQL and use \s to see if the changes were successful
Mysql>\s ... Server Characterset:utf8 Db characterset:utf8 Client characterset:utf8 Conn. Characterset:utf8 ...
Edit MySQL default encoding under Ubuntu 16.04.1