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

What are the MySQL character set and proofreading rules

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article introduces the knowledge of "what are the MySQL character set and proofreading rules". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

View all available character sets:

Mysql > show character set

+-- +

| | Charset | Description | Default collation | Maxlen | |

+-- +

| | utf8 | UTF-8 Unicode | utf8_general_ci | 3 |

View character set (character): how to save and proofread rules (collation): how to compare strings

Select * from information_schema.character_sets

Proofread rules

Mysql > show collation like'% gbk%'

+-- +

| | Collation | Charset | Id | Default | Compiled | Sortlen | |

+-- +

| | gbk_chinese_ci | gbk | 28 | Yes | Yes | 1 |

| | gbk_bin | gbk | 87 | | Yes | 1 | |

+-- +

2 rows in set (0.00 sec)

Name the setting:

Character set name begins with +:

_ ci (case insensitive)

_ cs (case sensitive)

_ bin (binary, comparison character value, insensitive to case)

Example:

Select case when 'A' COLLATE utf8_general_ci='a' collate utf8_general_ci then 1 else 0 end

one

-- the proofreading rule is that ci time is the same as An and a

Select case when 'A' COLLATE utf8_bin='a' collate utf8_bin then 1 else 0 end

0

Setting of Mysql character set

SERVER server category, DB data level, TABLE table level, field level

SERVER server character set and proofreading rules

1. My.cnf (ini) configuration

[mysql]

Character-set-server=utf8

two。 Start options

Mysqld-character-set-server=utf8

3. Specify when editing

Cmake. -DDEFAULT_CHARSET=utf8

If none of the above is specified, use: latin1

Mysql > show variables like 'character_set_server%'

+-+ +

| | Variable_name | Value |

+-+ +

| | character_set_server | utf8 |

+-+ +

1 row in set (0.00 sec)

Mysql > show variables like 'collation_server%'

+-+ +

| | Variable_name | Value |

+-+ +

| | collation_server | utf8_general_ci |

+-+ +

1 row in set (0.00 sec)

DB database character set proofreading rules

Alter database can be modified at the time of data creation, but existing data will not be modified.

1 > if DB character set and proofreading rules are specified, use the

2 > if the DB character set is specified and no proofreading is specified, use the character set default proofreading

3 > if DB proofreading is specified and no character set is specified, use proofreading related character sets

4 > if DB character set and proofing are not configured, use server character set and proofreading

Mysql > show variables like 'character_set_database%'

+-+ +

| | Variable_name | Value |

+-+ +

| | character_set_database | utf8 |

+-+ +

1 row in set (0.00 sec)

Mysql > show variables like 'collation_database%'

+-+ +

| | Variable_name | Value |

+-+ +

| | collation_database | utf8_general_ci |

+-+ +

1 row in set (0.00 sec)

Table character set and proofreading

CREATE TABLE `t` (

`id` varchar (100) DEFAULT NULL

`context` text

) ENGINE=InnoDB DEFAULT CHARSET=utf8

Specify when table is built, if the db character set is not set

Connection character set

Character_set_client client character set

Character_set_connection connection character set

Character_ser_results returns the character set

The three parameters are guaranteed to be the same, and the input and output of the guarantee are normal.

Settings:

[mysql]

Default-character-set=utf8

Can be configured uniformly:

Set names utf8

Mandatory setting character set

Select _ utf8 'character set', _ big5 'character set'

This is the end of the content of "what are the MySQL character set and proofreading rules". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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