Home >Backend Development >PHP Tutorial >Character sets in MySQL
Character set: It describes the encoding used when transmitting graphics or text. It is called Character set.
The relationship between graphics or text and encoding:
is like the following:
"Word" => 10010001 110000111
Encoding of data storage:
Data is stored on the server side, Who decides which way to encode and store it?
Constraints will eventually be mapped to the field level, so it is the field that determines the encoding.
Determining the encoding of the data is determined by the following scheme:
1. If the field specifies encoding, it is determined by the field,
2. If the field is not specified, just look at the table. If it is specified, the encoding will be determined. 3. If the encoding is not specified in the table, just look at the library. If it is determined, the encoding will be determined by the server. 4. If the library does not have the encoding, the server will Decide by yourself.
Are you sure that the following is the server encoding:
Typical encoding: gbk, utf8
Client operation, query encoding:
There are two important encodings when the client interacts with the server:
1. The encoding of the data sent by the client
2. The client accepts the encoding of the server
You can use "show variables like "character_set_%"; to display the variables starting with set and they will have the above two values ,
can only be in the form of gbk under the command line client
Use set variable name = variable value to change the variable value
set names gbk is a quick operation. The above two configurations are changed to the target encoding at the same time!
set names gbk|utf8 depends on the encoding accepted by the client!The overall process is:
setnames gbk|utf8