MySQL学习笔记四:字符集

时间:2023-01-08 16:25:24

1.字符集就是字符和其编码的集合,查看数据库支持的字符集

show character set

2.查看服务端启动时默认的字符集

mysql> show variables like 'character_set_%';
+--------------------------+-------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\MySQL\MySQL Server 5.5\share\charsets\ |
+--------------------------+-------------------------------------------+

3.设置当前客户端会话字符集

set names utf8 or set character set 'charset_name'

4.在保存时指定字符集

create database student charser gb2312  -----数据库级粒度-------
create table db_name(....)engine=MyISAM default charset=utf8 ----表级粒度-------
col_name character set utf8 -----列级粒度------

5.设置全局粒度的默认字符集

set global character_set_server=utf8