Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of mysql garbled code under linux

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to solve the problem of mysql garbled under linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The project interacts with the server, accesses the server-side jsp,jsp through post, accesses the server-side mysql database, and finally returns the Chinese characters to the client side with garbled code.

In the whole process, there may be three reasons for errors: no coding or mismatch in post, problems in jdbc, and problems in the initial code system of mysql under linux.

After tedious investigation, it is finally determined that the problem is mysql coding. The following describes how to solve the problem of Chinese garbled codes in mysql under linux.

First enter mysql command line mode and type mysql-uroot-p to enter. Then type SHOW VARIABLES LIKE 'character_set_%'

If the display is similar to this:

+-- +-+ | 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 | / alidata/server/mysql-5.1.73/share/charsets/ |

Has been modified correctly, and the default initial setting of mysql is latin1 rather than utf8.

One solution is to change the property of the table to utf8 or add DEFAULT CHARSET=utf8 at the end of the table when you create the table. Set the table to utf8 code. Such a method may not work.

The most fundamental solution is to open the mysql configuration file to modify. The mysql configuration file under linux is named my.cnf and the directory is / etc/my.cnf. After opening it, follow the following steps:

-- add three lines under the [mysqld] tag: default-character-set = utf8character_set_server = utf8lower_case_table_names = 1 / / the table name is case-insensitive (this has nothing to do with coding)-- add a line default-character-set = utf8-- under the [mysql] tag, a line default-character-set = utf8-- under the [mysql.server] tag, and a line default-character-set under the [mysqld_safe] tag. = utf8-- add a line default-character-set = utf8 under the [client] tag

It doesn't matter if you can't find all the above labels. Open the mysql command line again, and if latin1 still exists after executing SHOW VARIABLES LIKE 'character_set_%';, execute the following command under the mysql command line:

Set character_set_client = utf8

Set character_set_server = utf8

Set character_set_connection = utf8

Set character_set_database = utf8

Set character_set_results = utf8

Set collation_connection = utf8_general_ci

Set collation_database = utf8_general_ci

Set collation_server = utf8_general_ci

The target result can be obtained by executing the above show command after execution.

After setting up, you need to restart mysql and restart the command / etc/init.d/mysqld restart.

The original data table needs to be deleted and rebuilt.

It's finally done, it's done.

Summary

1. Modify the / etc/my.cnf file by adding the following lines:

[client] # pipe=# socket=MYSQLport=3306default-character-set=utf8 [mysql] no-beep# default-character-set=default-character-set=utf8# SERVER SECTION#-# The following options will be read by the MySQL Server. Make sure that# you have installed the server correctly (see above) so it reads this # file.# server_type= 3 [mysqld] character_set_server=utf8

2. Restart the mysql service:

Service mysql stop;service mysql status;service mysql start; or service mysql restart; are all the contents of this article entitled "how to solve the problem of mysql garbled under linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report