character set
View character sets in MySQL
Basic syntax:
1 show character set;
View the default character set in MySQL
Basic syntax:
1 show variables like ‘character_set%’;
Use character set to solve garbled problem
①Tell the server that what the client is passing is GBK format (the insert operation has an effect)
1 set character_set_client=GBK
②Tell the server that the client can only accept GBK format (the query operation is effective)
1 set character_set_results=GBK
But pay special attention, set can only be temporary, only valid in the current session, the next time you reopen the CMD terminal, it will be invalid.
But in practical applications, we don't need to bother to set the above two options separately, we can achieve the above effects with just one statement:
1 set names gbk;
proof set
1 Proofreading: In fact, it is to compare the data, and the proofreading set is the way of comparing MySQL data. 2 _bin : Binary collation set, use binary to compare data (ASCII code) 3 _ci : case insensitive, case insensitive when comparing, case insensitive 4 _cs: case sensitive, case sensitive when comparing, strict distinction case
View Collation Sets in MySQL
Basic syntax:
1 show collation;
MySQL Proofset Demo
1 create table sh_bin( 2 s char(1) 3 )charset=utf8 collate utf8_bin 4 5 insert into sh_bin values ('a'),('b'),('A'),('B'); 6 7 8 9 create table sh_ci( 10 s char(1) 11 )charset=utf8 collate utf8_general_ci 12 13 insert into sh_ci values ('a'),('b'),('A'),('B');
Sort data in different proof set data tables
Basic syntax:
1 select * from data table order by field name [ asc|desc ] 2 parameter description: 3 asc : ascending order, from 0 - 100 , the default sorting used 4 desc : descending order, from 100 - 0
sh_bin sorting results:
1 select * from sh_bin order by s asc ; 2 result: A < B < a < b ASCII code comparison
sh_ci sort result:
1 select * from sh_ci order by s asc ; 2 result: a A b B case insensitive
#####################################################################