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

Detailed explanation of HTML basics (Part 2)

1. List The list ul container is loaded with a fo...

Vue realizes web online chat function

This article example shares the specific code of ...

A brief discussion on several situations where MySQL returns Boolean types

mysql returns Boolean type In the first case, ret...

vue+springboot realizes login function

This article example shares the specific code of ...

Introduction to the usage of exists and except in SQL Server

Table of contents 1. exists 1.1 Description 1.2 E...

How to create a responsive column chart using CSS Grid layout

I have been playing around with charts for a whil...

MySQL optimization: how to write high-quality SQL statements

Preface There are a lot of information and method...

The best way to solve the 1px border on mobile devices (recommended)

When developing for mobile devices, you often enc...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

Docker configuration Alibaba Cloud Container Service operation

Configuring Alibaba Cloud Docker Container Servic...

Background image cache under IE6

CSS background image flickering bug in IE6 (backg...

Detailed explanation of React event binding

1. What is In react applications, event names are...

Example of implementing dynamic verification code on a page using JavaScript

introduction: Nowadays, many dynamic verification...