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

How to draw a vertical line between two div tags in HTML

Recently, when I was drawing an interface, I enco...

JavaScript realizes the effect of mobile modal box

This article example shares the specific code of ...

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

A simple way to implement Vue's drag screenshot function

Drag the mouse to take a screenshot of the page (...

Detailed explanation of encoding issues during MySQL command line operations

1. Check the MySQL database encoding mysql -u use...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...

1 minute Vue implements right-click menu

Table of contents Rendering Install Code Implemen...

Simple Implementation of HTML to Create Personal Resume

Resume Code: XML/HTML CodeCopy content to clipboa...

How to modify the forgotten password when installing MySQL on Mac

1. Install MySQL database on mac 1. Download MySQ...

How to clear the validation prompt in element form validation

Table of contents Problem scenario: Solution: 1. ...

Improving the effect of hyperlinks in web design and production

Hyperlinks enable people to jump instantly from pa...

PostgreSQL materialized view process analysis

This article mainly introduces the process analys...

Use Javascript to develop sliding-nav navigation plug-in with sliding bar effect

Table of contents 1. Introduction 2. Usage 3. Dev...