Linux set MySQL database encoding

Source: Internet
Author: User

After reloading the system, to install a MySQL server, found to add data, has been wrong, check its cause, the original encoding problem. Google a bit, but it is not the same, maybe the database version of the problem it.

To view the database version:

Select version ();

Show: ' 5.7.15-0ubuntu0.16.04.1 '

Official Documentation: Mysql document

1. View Database encoding

 like ' character% ';

Show Results:

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/
Character_set_client for the client code, character_set_connection for the establishment of the connection using the encoding; character_set_database database encoding; character_set_ Results the encoding of the result set; the encoding of the Character_set_server database server;

As long as the above four is guaranteed to use the same encoding method, there will be no garbled problem.

2. Set the database encoding

Divided into two parts: setting the database server encoding and setting the database encoding

Setting the database encoding is simple, when you create a database, you can specify the encoding;

If you set the server encoding, you need to modify the configuration file. The configuration file path is:/ETC/MYSQL/MYSQL.CONF.D

Locate [mysqld], and after adding the following code, restart the server.

character - Set -Server=utf8collation-Server=utf8_general_ci

3. Restart the database

Service MySQL Restart

Linux set MySQL database encoding

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.