In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How to solve the problem of garbled code in sql command query? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
MySQL command line query garbled solution:
The reasons for the occurrence of Chinese garbled codes in MySQL are as follows:
1.server itself setting problems, for example, still stuck in latin1
Language Family setting of 2.table (including character and collation)
3. The problem of setting the connection language of client programs such as php
It is strongly recommended that utf8,utf8 be compatible with all characters in the world.
Step 1: find the directory where mysql is installed and find the my.ini file
Step 2: open the my.ini file using notepad
Find this place to see if default-character-set is utf8 or not, just change it to utf8! (it would be nice to add this sentence directly without it in previous versions! )
# MySQL client library initialization.
[client]
Port=3306
[mysql]
Default-character-set=utf8
Step 3: enter: show variables like'%char%' in mysql database cmd
Step 4: change the coding mode of the original database: 1
two
three
four
Set character_set_database=utf8
Set character_set_server=utf8
Set character_set_client=gb2312
Set character_set_connection=gb2312
Step 5: the changed coding method:
Step 6: view the query results:
Step 6: try inserting Chinese data! Ok! It can be plugged in!
Step 7: solve the garbled code in select * from table, in fact, only use parts 4 and 7.
Change the coding method above:
Set character_set_results=gb2312; can be displayed normally!
About GBK, GB2312, UTF8
UTF- 8:Unicode Transformation Format-8bit, which allows BOM, but usually does not contain BOM. Is used to solve the international character of a multi-byte encoding, it uses 8 bits (that is, one byte) for English, 24 (three bytes) for Chinese coding. UTF-8 contains characters needed by all countries in the world. It is an international code with strong versatility. UTF-8-encoded text can be displayed on browsers that support the UTF8 character set in various countries. For example, if it is a UTF8 code, Chinese can also be displayed on the English IE of foreigners, and they do not need to download the Chinese language support package of IE.
GBK is a standard compatible with GB2312 after expansion based on the national standard GB2312. The text coding of GBK is represented by double bytes, that is, both Chinese and English characters are represented by double bytes. In order to distinguish between Chinese characters, the highest bit is set to 1. GBK, which contains all Chinese characters, is a national code, and its versatility is worse than UTF8, but UTF8 occupies a larger database than GBD.
GBK, GB2312, etc., and UTF8 must be encoded by Unicode before they can be converted to each other:
GBK 、 GB2312--Unicode--UTF8
UTF8--Unicode--GBK 、 GB2312
For a website or forum, if there are more English characters, it is recommended to use UTF-8 to save space. But now many forum plug-ins generally only support GBK.
GB2312 is a subset of GBK, and GBK is a subset of GB18030
GBK is a collection of large characters including Chinese, Japanese and Korean characters
If it is a Chinese website recommending GB2312 GBK, there is still a problem sometimes.
In order to avoid all garbled code problems, UTF-8 should be used, and it is very convenient to support internationalization in the future.
UTF-8 can be thought of as a large character set, which contains the encoding of most of the text.
One of the benefits of using UTF-8 is that users in other regions (such as Hong Kong and Taiwan) can view your text without garbled code without installing simplified Chinese support.
Gb2312 is a simplified Chinese code
Gbk supports both simplified and traditional Chinese
Big5 supports traditional Chinese
Utf-8 supports almost all characters
First of all, analyze the situation of garbled code
Several character sets involved in MySQL
Character-set-server/default-character-set: server character set, which is used by default.
Character-set-database: database character set.
Character-set-table: database table character set.
The priority is increased in turn. So in general, you only need to set up character-set-server, and when you create databases and tables, you don't specify a character set, so you uniformly use the character-set-server character set.
Character-set-client: the character set of the client. The client default character set. When the client sends a request to the server, the request is encoded with this character set.
Character-set-results: the resulting character set. When the server returns the result or information to the client, the result is encoded in this character set.
On the client side, if no character-set-results is defined, the character-set-client character set is used as the default character set. So you only need to set the character-set-client character set.
To handle Chinese, you can set both character-set-server and character-set-client to GB2312, or to UTF8 if you want to handle multiple languages at the same time.
On the Chinese question of MySQL
The solution to garbled code is to set the following three system parameters of MySQL to the same character set as the server character set character-set-server before executing the SQL statement.
Character_set_client: the character set of the client.
Character_set_results: the resulting character set.
Character_set_connection: concatenation character set.
Set these three system parameters by sending a statement to MySQL: set names gb2312
Thank you for reading! After reading the above, do you have a general understanding of how to solve the problem of garbled codes in sql command queries? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.