How to change the character set encoding to UTF8 in MySQL 5.5/5.6 under Linux

How to change the character set encoding to UTF8 in MySQL 5.5/5.6 under Linux

1. Log in to MySQL and use SHOW VARIABLES LIKE 'character%'; to view the character set, as shown below:

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

The default character set for character_set_database and character_set_server is still latin1.

2. The simplest and most perfect modification method is to modify the character set key value in the my.cnf file of MySQL (pay attention to the configuration field details):

1. Add default-character-set=utf8 to the [client] field, as follows:

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8

2. Add character-set-server=utf8 to the [mysqld] field as follows:

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8

3. Add default-character-set=utf8 to the [mysql] field, as follows:

[mysql]
no-auto-rehash
default-character-set=utf8

After the modification is completed, restart the MySQL service with service mysql restart to make it take effect. Note: The [mysqld] field is different from the [mysql] field. No one has reported this online.

Use SHOW VARIABLES LIKE 'character%'; to check and find that the database encoding has been changed to utf8.

+--------------------------+----------------------------+
| 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/ |

+--------------------------+----------------------------+

The above method of changing the character set encoding to UTF8 in MySQL 5.5/5.6 under Linux is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Steps to change mysql character set to UTF8 under Linux system

<<:  Rsync+crontab regular synchronization backup under centos7

>>:  Installation and use tutorial of Elasticsearch tool cerebro

Recommend

Optimized implementation of count() for large MySQL tables

The following is my judgment based on the data st...

JS implements WeChat's "shit bombing" function

Hello everyone, I am Qiufeng. Recently, WeChat ha...

XHTML Basic 1.1, a mobile web markup language recommended by W3C

W3C recently released two standards, namely "...

Introduction to NFS service construction under Centos7

Table of contents 1. Server 2. Client 3. Testing ...

Control the light switch with js

Use js to control the light switch for your refer...

Vue+Router+Element to implement a simple navigation bar

This project shares the specific code of Vue+Rout...

The easiest way to reset mysql root password

My mysql version is MYSQL V5.7.9, please use the ...

Ubuntu 20.04 Chinese input method installation steps

This article installs Google Input Method. In fac...

Comparison of two implementation methods of Vue drop-down list

Two implementations of Vue drop-down list The fir...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

Use of provide and inject in Vue3

1. Explanation of provide and inject Provide and ...

Vue implements the method example of tab routing switching component

Preface This article introduces the use of vue-ro...

Solution to 1045 error in mysql database

How to solve the problem of 1045 when the local d...

How to recover accidentally deleted messages files in Linux

If there are files that are being used by a proce...