Home >Database >Mysql Tutorial >How to solve the problem of mysql jsp garbled characters

How to solve the problem of mysql jsp garbled characters

藏色散人
藏色散人Original
2021-12-16 11:29:591910browse

Mysql jsp garbled solution: 1. Use "show variables like 'character%';" to view the relevant encoding set of the current database; 2. Use "set names gbk;" to set the encoding related to the client Just set.

How to solve the problem of mysql jsp garbled characters

The operating environment of this article: windows7 system, mysql5.5 version, Dell G3 computer.

How to solve the mysql jsp garbled problem?

JSP's MySQL solves the problem of Chinese garbled characters when inserting data

When inserting a piece of data with Chinese characters into the MySQL database, the shape is insert into employee values(null,'Zhang San','female','1995-10-08','2015-11-12','Sales',2000,'He is a good employee!'); When garbled characters appear, you can use the statement show variables like 'character%'; to view the relevant encoding set of the current database.

As you can see from the above figure, MySQL uses character sets in six places, namely: client, connection, database, results, server, system. Among them, related to the server: database, server, system (can never be modified, it is utf-8); related to the client: connection, client, results .

How to solve the problem of mysql jsp garbled characters

After understanding the above information, let’s analyze the cause of the garbled characters. The problem lies in the current CMD. In the client window, because the current CMD client input uses GBK encoding, and the encoding format of the database is UTF-8, inconsistent encoding results in garbled characters. The encoding format of the current CMD client cannot be modified, so the encoding set of connection, client, and results can only be modified to inform the server that the currently inserted data uses GBK encoding, and although the server's database is UTF-8 encoded, it can identify 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 setting is completed, the problem of garbled data inserted or displayed by the client can be solved, but we will soon find that this form of setting will only be used in the current window. Effective. When the CMD client is reopened after the window is closed, garbled characters will appear again. So, how to set it up once and for all? There is a my.ini in the MySQL installation directory. Configuration file, by modifying this configuration file you can solve the garbled problem once and for all. In this configuration file [mysql] is related to client configuration, [mysqld] is related to 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 re- Just start the MySQL service.

【Related recommendations: mysql video tutorial

The above is the detailed content of How to solve the problem of mysql jsp garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn