How to solve the mysql insert garbled problem

How to solve the mysql insert garbled problem

Problem description:

When inserting Chinese characters into MySQL, or Chinese characters are displayed normally in MySQL, but jsp displays Chinese characters in MySQL in the foreground, it is garbled.

Solution:

Enter the mysql console and execute the following command:

SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8';

More solutions:

client The character set used by the client.
connection Set the character set type for connecting to the database. If the program does not specify the character set type used to connect to the database, the default character set on the server is used.
database The character set used by a library in the database server. If it is not specified when the library is created, the character set specified when the server is installed will be used.
results The character set used by the database when returning data to the client. If not specified, the server's default character set is used.
server The default character set specified when the server is installed.
system The character set used by the database system.

The CMD client input uses GBK encoding, while the database encoding format is UTF-8. The inconsistent encoding results in garbled characters. The current encoding format of the CMD client cannot be modified, so you can only modify the encoding set of connection, client, and results to inform the server that the currently inserted data uses GBK encoding. Although the server database uses UTF-8 encoding, it can recognize the GBK encoded data notified to the server and automatically convert it to UTF-8 for storage. You can use the following statement to quickly set the encoding set related to the client:
set names gbk;

After the settings are completed, the garbled problem of data inserted or displayed on the client can be solved, but we will soon find that this form of setting is only valid in the current window. When the window is closed and the CMD client is reopened, the garbled problem will appear again; so, how to make a once-and-for-all setting? There is a my.ini configuration file in the MySQL installation directory. By modifying this configuration file, the garbled character problem can be solved once and for all. In this configuration file, [mysql] is related to the client configuration, and [mysqld] is related to the server configuration. The default configuration is as follows:

[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8

At this time, you only need to change the default encoding default-character-set=utf8 to default-character-set=gbk and restart the MySQL service.

This is the end of this article on how to solve the MySQL insert garbled problem. For more information on how to solve the MySQL insert garbled problem, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to solve the problem that mysql cannot be closed
  • Solve the problem that the MySQL database crashes unexpectedly, causing the table data file to be damaged and unable to start
  • This article solves the compatibility problem between Django 2.2 and MySQL
  • A brief discussion on the datetime format when exporting table data from MySQL to Excel
  • Quickly solve the problems of incorrect format, slow import and data loss when importing data from MySQL
  • Quickly solve the problem of garbled characters and jump lines in mysql exported scv files
  • Modification of time zone problem of MySQL container in Docker
  • pyMySQL SQL statement parameter passing problem, single parameter or multiple parameter description
  • MySQL 5.7.30 Installation and Upgrade Issues Detailed Tutorial
  • Solution to the problem of MySQL data delay jump

<<:  JavaScript to achieve mouse tailing effect

>>:  Implementing simple tabs with js

Recommend

You really need to understand the use of CSS variables var()

When a web project gets bigger and bigger, its CS...

How to completely delete and uninstall MySQL in Windows 10

Preface This article introduces a tutorial on how...

MySql learning day03: connection and query details between data tables

Primary Key: Keyword: primary key Features: canno...

Notes on MySQL case sensitivity

Table of contents MySQL case sensitivity is contr...

Small problem with the spacing between label and input in Google Browser

Code first, then text Copy code The code is as fol...

jQuery implements percentage scoring progress bar

This article shares the specific code of jquery t...

Mini Program to Implement Paging Effect

This article example shares the specific code for...

Analysis and solution of flex layout collapse caused by Chrome 73

Phenomenon There are several nested flex structur...

Solution to the Chinese garbled characters problem in MySQL under Ubuntu

Find the problem I have been learning Django rece...

Linux echo text processing command usage and examples

The description of echo in the Linux help documen...

Example code for realizing charging effect of B station with css+svg

difficulty Two mask creation of svg graphics Firs...

HTML head tag detailed introduction

There are many tags and elements in the HTML head ...