In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Mysql how to view the code, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
I.
Character set viewed
Show variables like 'character\ _ set\ _%'
Output:
+-+ +
| | Variable_name | Value |
+-+ +
| | character_set_client | latin1 |
| | character_set_connection | latin1 |
| | character_set_database | latin1 |
| | character_set_filesystem | binary |
| | character_set_results | latin1 |
| | character_set_server | latin1 |
| | character_set_system | utf8 |
+-+ +
Combined with the following coding table, we find the coding of the current database system:
Latin1_bin
Western Europe (multilingual), binary
Binary
Binary system
The above is the result code set of my view in the linux environment. I now view the results of the code set on the WIN platform, such as:
+-+ +
| | 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 |
+-+ +
Why are there inconsistencies? On my computer is the display of UTF-8. And on LINUX, it's actually
Second, modify its code by command
Create the character set of the specified database
Create database mydb character set utf-8;# specifies its encoding directly
Modify directly through the command
Set character_set_client=utf8
Set character_set_connection=utf8
Set character_set_database=utf8
Set character_set_results=utf8
Set character_set_server=utf8
Inquire after you have finished the modification.
Show variables like 'character\ _ set\ _%'
+-+ +
| | 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 |
+-+ +
As a result, all the adjustments have been changed to UTF-8!
After the modification, I see that select * from address_address; has garbled codes! Django is also garbled.
Third, solve the problem of garbled codes in data import and export.
# create database nginxdjango
# use nginxdjango
# show variables like 'character\ _ set\ _%'
# the printout is as follows
+-+ +
| | Variable_name | Value |
+-+ +
| | character_set_client | latin1 |
| | character_set_connection | latin1 |
| | character_set_database | latin1 |
| | character_set_filesystem | binary |
| | character_set_results | latin1 |
| | character_set_server | latin1 |
| | character_set_system | utf8 |
+-+ +
It's still latin coded.
OK . I'll set the code for it.
Set character_set_client=utf8
Set character_set_connection=utf8
Set character_set_database=utf8
Set character_set_results=utf8
Set character_set_server=utf8
Query its encoding format again: +-- +-+.
| | 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 |
+-+ +
Now import the data.
Source / python/django/sql/nginxdjango.sql
Among them, nginxdjango.sql is also encoded in utf-8 format!
Import into the database to check it is still garbled, but the program runs normally!
Types of MySQL character set encoding
The difference between gb2312_chinese_ci and gbk_chinese_ci and gb2312_bin,gbk_bin
Gb2312_chinese_CI: only simplified Chinese is supported
Gb2312_BIN: and gb2312_bin is a subset of gb2312_chinese_ci.
And gb2312_BIN is binary storage. The meaning of case-sensitive database coding format is different.
Gbk_chinese_CI supports simplified Chinese and traditional Chinese
Gbk_bin interpretation corresponds to gb2312_BIN corresponding to gbk_chinese_CI
PS:GBK includes two types: simplified and traditional.
New article: 2010-03-09
The default character set in MySQL has four levels: server level, database level, and table level. Finally, it is the field-level character set setting. Note that the first three are default settings and do not code that your fields will eventually use this character set setting. So we recommend using show create table table; or show full fields from tableName; to check the character set settings for the fields in the current table.
The character set on the connection environment in MySQL is set on the Client side. Connection, results through these parameters, MySQL will know what character set your client tool uses and what character set the result set should be. In this way, MySQL will do the necessary translation, once these parameters are wrong, it will naturally lead to string conversion errors in the process of transfer. Basically 99% of the garbled code is made up of something.
1. The character set settings for the fields in the database table. Show create table TableName or show full columns from tableName
Mysql > show create table T1
Mysql > show full columns from T1; check the encoding type of the column
3. View the encoding format of the database
Show create database test
Output: CREATE DATABASE `test` / *! 40100 DEFAULT CHARACTER SET utf8 * /
two。 The current connection system parameter show variables like 'char%'
Mysql > show variables like 'char%'
1. In Chinese, please make sure that the character set of this field in the table is compatible with Chinese:
Big5 | Big5 Traditional Chinese
Gb2312 | GB2312 Simplified Chinese
Gbk | GBK Simplified Chinese
Utf8 | UTF-8 Unicode
[other additions]
Modify the character set of the database
Mysql > use mydb
Mysql > alter database mydb character set utf-8
Create the character set of the specified database
Mysql > create database mydb character set utf-8
2010-05-02 newly added
Show variables like 'character\ _ set\ _%'; three of the items seen are affected by the client
Character_set_client
Character_set_connection
Character_set_results
After reading the above, have you mastered the method of how to view the code in Mysql? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.