Solution to the garbled code problem in MySQL 5.x

Solution to the garbled code problem in MySQL 5.x

MySQL is a commonly used open source database software, but it does not seem to be very friendly to first-time users. The default character set in MySQL5.x version is latin1, which is the ISO-8859-1 character set we know. This character set encoding does not include Chinese characters, so when we use it, Chinese characters will appear garbled. This can be solved by modifying the database default character set.

Enter the MySQL command line:

mysql> show variables like '%colla%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | gbk_chinese_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set, 1 warning (0.00 sec)

mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set, 1 warning (0.00 sec)

You can see that the default character set is now latin1

Find the MySQL configuration file. The configuration file in Windows is my.ini. My computer is located at C:\ProgramData\MySQL\MySQL Server 5.7. The file that needs to be modified in Linux is my.conf. The specific path depends on your actual installation location. Modify the configuration in the following nodes respectively:

The configuration of the [client] node in the 5.7 I use needs to be added, and the other two nodes [mysql] and [mysql] need to open the comments and change them to utf8.

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysql]
character_set_server=utf8

Then restart MySQL

net stop mysql
net start mysql

Check the character set again, all have been changed to utf8 character set

mysql> show variables like '%colla%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | gbk_chinese_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set, 1 warning (0.00 sec)

mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set, 1 warning (0.00 sec)

To ensure encoding consistency, you can also specify the character set when creating a database or table, and specify the connection parameters after the connection string:

?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL 8.0.24 version installation and configuration method graphic tutorial
  • Some improvements in MySQL 8.0.24 Release Note
  • Implementation of MySQL's MVCC multi-version concurrency control
  • The best solution for resetting the root password of MySQL 8.0.23
  • About the configuration problem of MyBatis connecting to MySql8.0 version
  • How to solve the problem that Seata cannot use MySQL 8 version
  • Detailed explanation of DBeaver connecting to MySQL version 8 and above and solving possible problems
  • Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA
  • Detailed tutorial on installing MySQL 8.0.20 database on CentOS 7
  • Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above
  • Solve the installation problem of mysql8.0.19 winx64 version
  • Django 2.2 and PyMySQL version compatibility issues
  • Steps to install MySQL 5.7 in binary mode and optimize the system under Linux
  • Installation of various versions of MySQL 8.0.18 and problems encountered during installation (essence summary)
  • Super detailed teaching on how to upgrade the version of MySQL

<<:  Vue implements the sample code of adding, deleting, modifying and checking the tree structure

>>:  Detailed explanation of Docker Swarm concepts and usage

Blog    

Recommend

Let's talk about Vue's mixin and inheritance in detail

Table of contents Preface Mixin Mixin Note (dupli...

How to count down the date using bash

Need to know how many days there are before an im...

Linux uses stty to display and modify terminal line settings

Sttty is a common command for changing and printi...

JavaScript MouseEvent Case Study

MouseEvent When the mouse performs a certain oper...

Vue3.0 routing automatic import method example

1. Prerequisites We use the require.context metho...

Example code for css flex layout with automatic line wrapping

To create a flex container, simply add a display:...

The difference between Display, Visibility, Opacity, rgba and z-index: -1 in CSS

We often need to control the hidden, transparent ...

MySQL trigger detailed explanation and simple example

MySQL trigger simple example grammar CREATE TRIGG...

How to completely uninstall node and npm on mac

npm uninstall sudo npm uninstall npm -g If you en...

Two usages of iFrame tags in HTML

I have been working on a project recently - Budou...

Discussion on the problem of iframe node initialization

Today I suddenly thought of reviewing the producti...

MySQL password modification example detailed explanation

MySQL password modification example detailed expl...

Element Table table component multi-field (multi-column) sorting method

Table of contents need: Problems encountered: sol...