TiDB字符集和时区

news/2024/11/8 9:29:50/

TiDB 字符集和时区

mysql> select @@version;

+--------------------------------------+

| @@version |

+--------------------------------------+

| 5.7.10-TiDB-v2.1.0-beta-179-g5a0fd2d |

+--------------------------------------+

1 row in set (0.00 sec)

mysql> show variables like 'coll%';

+----------------------+-------------------+

| Variable_name | Value |

+----------------------+-------------------+

| collation_connection | utf8_general_ci |

| collation_server | latin1_swedish_ci |

| collation_database | latin1_swedish_ci |

+----------------------+-------------------+

3 rows in set (0.01 sec)

mysql> show variables like 'char%';

+--------------------------+--------------------------------------------------------+

| Variable_name | Value |

+--------------------------+--------------------------------------------------------+

| character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |

| character_set_connection | utf8 |

| character_set_client | utf8 |

| character_set_system | utf8 |

| character_set_results | utf8 |

| character_set_filesystem | binary |

| character_set_server | latin1 |

| character_set_database | latin1 |

+--------------------------+--------------------------------------------------------+

8 rows in set (0.01 sec)

登录进入默认的为utf8.

创建使用默认的字符集和排序规则的表:

mysql> create database wuhan;

Query OK, 0 rows affected (0.12 sec)

mysql> create table wuhan.city(id int not null auto_increment primary key,cityname varchar(20));

Query OK, 0 rows affected (0.14 sec)

mysql> show create table wuhan.city\G

*************************** 1. row ***************************

Table: city

Create Table: CREATE TABLE `city` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`cityname` varchar(20) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

1 row in set (0.00 sec)

可以看到使用的默认字符集为utf8,排序规则为utf8_bin。

创建指定字符集和排序规则的表:

mysql> show create table wuhan.city2\G

*************************** 1. row ***************************

Table: city2

Create Table: CREATE TABLE `city2` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`cityname` varchar(20) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci

1 row in set (0.00 sec)

使用latin1字符集和排序规则的表。

mysql> create table wuhan.city3(id int not null auto_increment primary key,cityname varchar(20)) character set latin1 COLLATE latin1_general_ci;

Query OK, 0 rows affected (0.14 sec)

mysql> show create table wuhan.city3\G

*************************** 1. row ***************************

Table: city3

Create Table: CREATE TABLE `city3` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`cityname` varchar(20) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

1 row in set (0.00 sec)

---查询当前数据库的字符集和排序规则:

mysql> SELECT @@character_set_database, @@collation_database;

+--------------------------+----------------------+

| @@character_set_database | @@collation_database |

+--------------------------+----------------------+

| latin1 | latin1_swedish_ci |

+--------------------------+----------------------+

1 row in set (0.01 sec)

mysql> use wuhan

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> SELECT @@character_set_database, @@collation_database;

+--------------------------+----------------------+

| @@character_set_database | @@collation_database |

+--------------------------+----------------------+

| utf8 | utf8_bin |

+--------------------------+----------------------+

1 row in set (0.00 sec)

--查询表的排序规则:

mysql> SELECT t.TABLE_SCHEMA,t.TABLE_NAME,t.TABLE_COLLATION

-> FROM information_schema.TABLES t WHERE t.TABLE_SCHEMA='wuhan';

+--------------+------------+-------------------+

| TABLE_SCHEMA | TABLE_NAME | TABLE_COLLATION |

+--------------+------------+-------------------+

| wuhan | city | utf8_bin |

| wuhan | city2 | utf8_general_ci |

| wuhan | city3 | latin1_general_ci |

+--------------+------------+-------------------+

第二部分 设置字符集和排序规则:

设置为utf8,排序规则则自动设置为utf8_bin.

set names 'utf8';

等同于:

SET character_set_client = utf8;

SET character_set_results = utf8;

SET character_set_connection = utf8;

需要另外设置:

set global collation_server=utf8_bin;

SET CHARACTER SET 'charset_name'

等同于:

SET character_set_client = charset_name;

SET character_set_results = charset_name;

SET collation_connection = @@collation_database;

mysql> show variables like 'char%';

+--------------------------+--------------------------------------------------------+

| Variable_name | Value |

+--------------------------+--------------------------------------------------------+

| character_set_connection | utf8 |

| character_set_client | utf8 |

| character_set_system | utf8 |

| character_set_database | utf8 |

| character_set_results | utf8 |

| character_sets_dir | /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ |

| character_set_filesystem | binary |

| character_set_server | utf8 |

+--------------------------+--------------------------------------------------------+

8 rows in set (0.01 sec)

mysql> show variables like 'coll%';

+----------------------+----------+

| Variable_name | Value |

+----------------------+----------+

| collation_connection | utf8_bin |

| collation_database | utf8_bin |

| collation_server | utf8_bin |

+----------------------+----------+

3 rows in set (0.01 sec)

结论:

经过验证默认的字符集就是utf8,排序规则是utf8_bin.

在 TiDB 中实际上 utf8 被当做成了 utf8mb4 来处理。

当前tiBD支持的字符集和校验规则可以分别通过如下方式查询:

mysql> SHOW CHARACTER SET;

+---------+---------------+-------------------+--------+

| Charset | Description | Default collation | Maxlen |

+---------+---------------+-------------------+--------+

| utf8 | UTF-8 Unicode | utf8_bin | 3 |

| utf8mb4 | UTF-8 Unicode | utf8mb4_bin | 4 |

| ascii | US ASCII | ascii_bin | 1 |

| latin1 | Latin1 | latin1_bin | 1 |

| binary | binary | binary | 1 |

+---------+---------------+-------------------+--------+

5 rows in set (0.00 sec)

mysql> SHOW COLLATION;

目前支持排序规则219个。

但是上面的设置在tiDB重启后就使用了默认的字符集和和排序规则。

默认的字符集为utf8.TiDB目前不支持将字符集合排序规则写入到配置文件中。

时区支持:

TiDB 使用的时区由 time_zone 全局变量和 session 变量决定。 time_zone 的初始值是机器当前的系统时区为SYSTEM。

--查询时区:

mysql> SELECT @@global.time_zone, @@session.time_zone;

+--------------------+---------------------+

| @@global.time_zone | @@session.time_zone |

+--------------------+---------------------+

| SYSTEM | SYSTEM |

+--------------------+---------------------+

1 row in set (0.00 sec)

对于中国用户,按照默认使用即可。


http://www.ppmy.cn/news/833574.html

相关文章

Qt绘制指针时钟

Qt绘制指针时钟 什么是Qt? Qt是一款跨平台的C应用程序开发框架,它提供了一套完整的工具和库,可以帮助开发者快速构建高质量的应用程序。Qt支持多种操作系统和开发语言,包括Windows、Linux、macOS、Android、iOS等,同…

Android 仿京东【购物车】包含MVP.网络拦截器.防内存泄露...

一言不合就上图 首先在Manifest清单里面写权限&#xff1a; <uses-permission android:name"android.permission.INTERNET" /><uses-permission android:name"android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:nam…

Golang环境搭建指南(Windows和linux)

前言&#xff1a; go语言和Java&#xff0c;Python&#xff0c;C语言等等基本一样&#xff0c;也是需要在系统内集成语言环境的。语言基本都一样&#xff0c;支持各种系统架构&#xff0c;比如&#xff0c;mac&#xff0c;Windows&#xff0c;linux系统支持。本文仅以最为常用…

【项目 进程1】2.1 进程概述 2.2 进程状态转换

文章目录 2.1进程概述程序和进程**时间片****并行和并发****进程控制块(PCB)** 2.2进程状态转换**进程的状态** **进程相关命令****实时显示进程动态** 2.1进程概述 程序和进程 程序是包含一系列信息的文件&#xff0c;这些信息描述了如何在运行时创建一个进程&#xff1a; …

电线接头的地方只用黑色胶带缠了一圈会怎样

看房子装修好不好&#xff0c;除了表面&#xff0c;它的“内在”&#xff0c;即水电改造也很重要。近日&#xff0c;一位客户问我&#xff0c;他家在进行水电装修时&#xff0c;发现工人们在电线管内有部分电线接头的地方&#xff0c;只是用黑色胶带缠了一圈。虽然工人们一直强…

敷料dressing和绷带、纱布的区别

一般来讲&#xff0c;绷带更多地是用于将敷料保持在适当位置的支撑装置。 敷料通常直接与伤口或伤口接触&#xff0c;并且与绷带的不同之处在于其旨在愈合&#xff0c;而绷带仅支持愈合。 烧伤&#xff0c;擦伤&#xff0c;割伤或其他伤害可能需要特殊类型的敷料。 根据尺寸&am…

关于敷铜全连接和十字连接

敷铜时&#xff0c;地层要采用十字连接&#xff0c;因为一般在TOP或者BOTTOM层会全敷铜&#xff0c;采用十字连接会降低散热速度。 而电源层要采用全连接。