Home  >  Article  >  Database  >  How to use the character set character in MySQL database

How to use the character set character in MySQL database

WBOY
WBOYforward
2023-06-02 13:55:061291browse

1. Character set character

  • Charactercharacter is the general name for various characters and symbols

  • Character encoding character code is a binary storage code in the computer for various symbols

  • Character set character set is a number of characters Collection of

Common character sets:

  • ASCII character set

  • GB2312 Character set

  • Unicode character set

2. Set the client character set

-- 设置客户端字符集编码
set names gbk;
-- 查看字符集编码设置
show variables like 'character_set_%';
+--------------------------+------------+
| Variable_name            | Value      |
+---------+-----------------------------+
| character_set_client     | gbk        |
| character_set_connection | gbk        |
| character_set_database   | utf8mb4    |
| character_set_filesystem | binary     |
| character_set_results    | gbk        |
| character_set_server     | utf8mb4    |
| character_set_system     | utf8       |
| character_sets_dir       | /usr/local/Cellar/mysql/8.0.16/share/mysql/charsets/ |
+--------------------------+------------+
-- 插入中文字符
insert into tb_teacher (name, age) values ('张三', 23);

MySQL There are three layers between MySQLd:

  • The client passes in data to the serverclient

  • service The end returns data to the clientserver

  • Connection between client and servercollection

##Variables:

  • character_set_client Client

  • character_set_connection Connection layer

  • character_set_database Database

  • character_set_results Result set

Modify variables:

set 变量名 = 值;
-- 修改单个变量
set character_set_client = gbk;
-- 设置字符集
set names gbk;
-- 等价于
set character_set_client = gbk; // 让服务器识别客户端传过去的数据
set character_set_connection = gbk; // 更好的帮助客户端与服务器端之间惊醒字符集转换
set character_set_results = gbk; // 告诉客户端服务器返回的数据

The above is the detailed content of How to use the character set character in MySQL database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete