-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# MySQL是如何打开和关闭表? | ||
|
||
## 时区和时间戳 | ||
|
||
MySQL是多线程软件,存在着多个客户端访问同一个表的并发场景, | ||
|
||
MySQL实例进程在启动时会根据配置文件my.cnf中对这四个参数的设置进行自适应的调整生效,由于MySQL在设置这四个参数时存在严格的顺序和依赖关系。 | ||
|
||
### 硬件时钟 | ||
https://dev.mysql.com/doc/refman/8.4/en/table-cache.html | ||
|
||
硬件时钟,又称实时时钟(Real Time Clock,RTC)或CMOS时钟,是独立的硬件设备(电池、电容元件等,一般是主板电池),保存的时间包括年、月、日、时、分、秒。 | ||
|
||
2016年之后的UEFI固件还能保存时区和是否使用夏令时。 | ||
|
||
**硬件时钟** 由BIOS电池供电,当计算机关机后,会继续运行,BIOS电池一般可使用几年,如果没电了,那BIOS中的数据会恢复出厂设置。 | ||
在打开一个表准备访问数据的时候,通常要先打开其数据字典,其中包含了字段信息,索引信息,默认值,字符集,统计数据,自增字段,自增锁等等信息。 | ||
|
||
在实际开发过程中,可能存在如下问题: | ||
其中某些在MySQL层,有些在Innodb层(比如统计信息),又比如字段类型在MySQL层和Innodb层的表示是不同的,实际上这包含3层信息: | ||
|
||
- MySQL 的安装规范中应该设置什么时区? | ||
|
||
- JAVA 应用读取到的时间和北京时间差了14个小时,为什么?怎么解决? | ||
- **table instance**:MySQL层相关的字典信息,每个会话独占由table share生成而来。在语句结束的时候释放,这里的释放并不是真正的释放,可能是缓存,其缓存的个数和table_open_cache和table_open_cache_instances有关,其缓存位置约定为table cache,内部为TABLE。 | ||
|
||
|
||
- **table share**:MySQL层相关字典的信息,整个数据库只有一份,每个表都包含一个。5.7来自FRM文件,8.0则来自新的SDI缓存相关字典信息。当没有table cache引用的时候会考虑释放,但是同前面一样,释放可能是缓存,缓存的个数和`table_definition_cache`有关,其缓存位置约定为`table def cache`,内部为TABLE_SHARED。 | ||
|
||
|
||
- **dict table**:Innodb层的信息,这个数据库只有一份,每个表都包含一个,其信息来自Innodb的数据字典,主要是SYS_TABLES/SYS_COLUMN等几个表。当没有table cache引用的时候会考虑释放,同样释放可能是缓存,缓存的个数依旧和table_definition_cache有关,其缓存位置约定为dict table cache,内部为dict_table_t | ||
|
||
|
||
- 已经运行一段时间的业务,修改 MySQL 的时区会影响已经存储的时间类型数据吗? | ||
|
||
- 迁移数据时会有导致时间类型数据时区错误的可能吗? | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters