Edit MySQL default encoding under Ubuntu 16.04.1

Source: Internet
Author: User
Tags mysql client

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.