修改主机时间对MySQL影响

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

背景

在装机实施时,BIOS忘记调整时间,导致服务器时间与CST不符合;待发现问题时,MySQL环境已经在运行,所以只能通过操作系统进行更改;但是更改完成后,MySQL进行重启时发生了问题。以下为问题复现和解决过程

测试环境

MySQL 5.7.24 CentOS 7.4

root@localhost : (none) 12:00:54> show variables like '%time_zone';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.01 sec)

root@localhost : (none) 12:00:56> show variables like 'log_time%';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| log_timestamps | SYSTEM |
+----------------+--------+
1 row in set (0.00 sec)

root@localhost : (none) 02:20:54> show variables like '%fast_shutdown';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| innodb_fast_shutdown | 2 |
+----------------------+-------+
1 row in set (0.00 sec)

测试过程

[root@localhost ~]# date
Tue Dec 4 11:06:55 CST 2018

[root@localhost ~]# ps -ef|grep mysql
mysql 5113 1 4 11:06 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 5160 1403 0 11:06 pts/0 00:00:00 grep --color=auto mysql

###主机向前修改时间
[root@localhost ~]# date -s 10:00
Tue Dec 4 10:00:00 CST 2018

[root@localhost ~]# date
Tue Dec 4 10:00:01 CST 2018

###停止MySQL
[root@localhost ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service

###查看错误日志,时间由11:00到10:00,出现了hang
[root@localhost ~]# tail -f /var/log/mysql/error.log
2018-12-04T11:06:52.731556+08:00 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2018-12-04T11:06:52.731564+08:00 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
...
2018-12-04T10:00:07.198925+08:00 0 [Note] InnoDB: FTS optimize thread exiting.
2018-12-04T10:00:07.199255+08:00 0 [Note] InnoDB: Starting shutdown...
2018-12-04T10:01:15.036504+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-04T10:02:22.191904+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-04T10:03:32.160278+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

解决1

###手动kill掉
[root@localhost ~]# ps -ef|grep mysqld
mysql 5234 1 0 12:00 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 5300 1886 0 12:04 pts/1 00:00:00 grep --color=auto mysqld

[root@localhost ~]# kill -9 5234 1

解决2

###手动修改时间(大于error.log最大的time)
[root@localhost ~]# date -s 12:00         
Tue Dec 4 12:00:00 CST 2018

###查看error日志,正常关闭
[root@localhost ~]# tail -f /var/log/mysql/error.log
2018-12-04T10:00:07.198780+08:00 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2018-12-04T10:00:07.198783+08:00 0 [Note] Shutting down plugin 'INNODB_TRX'
2018-12-04T10:00:07.198786+08:00 0 [Note] Shutting down plugin 'InnoDB'
2018-12-04T10:00:07.198925+08:00 0 [Note] InnoDB: FTS optimize thread exiting.
2018-12-04T10:00:07.199255+08:00 0 [Note] InnoDB: Starting shutdown...
2018-12-04T10:01:15.036504+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-04T10:02:22.191904+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-04T10:03:32.160278+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-04T12:00:00.032698+08:00 0 [Note] InnoDB: MySQL has requested a very fast shutdown without flushing the InnoDB buffer pool to data files. At the next mysqld startup InnoDB will do a crash recovery!
2018-12-04T12:00:00.847336+08:00 0 [Note] InnoDB: Shutdown completed; log sequence number 0
2018-12-04T12:00:00.849656+08:00 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2018-12-04T12:00:00.849693+08:00 0 [Note] Shutting down plugin 'MEMORY'
2018-12-04T12:00:00.849701+08:00 0 [Note] Shutting down plugin 'CSV'
2018-12-04T12:00:00.849706+08:00 0 [Note] Shutting down plugin 'sha256_password'
2018-12-04T12:00:00.849708+08:00 0 [Note] Shutting down plugin 'mysql_native_password'
2018-12-04T12:00:00.849808+08:00 0 [Note] Shutting down plugin 'binlog'
2018-12-04T12:00:00.850080+08:00 0 [Note] /usr/sbin/mysqld: Shutdown complete

原因

MySQL所在的服务器的时间更改,MySQL的缓存的时间戳依据的是主机的时间;在我们手动向前修改时间,会出现MySQL退出时要求清空比生成时间“还早”的缓存而导致了锁死。

验证

[root@yuelei1 etc]# date;date -s 14:07
Fri Dec 14 14:09:39 CST 2018
Fri Dec 14 14:07:00 CST 2018

[root@yuelei1 etc]# date;service mysqld stop
Fri Dec 14 14:07:02 CST 2018
Redirecting to /bin/systemctl stop mysqld.service

[root@yuelei1 ~]# tail -f /var/log/mysql/error.log
...
2018-12-14T14:07:03.272305+08:00 0 [Note] Shutting down plugin 'INNODB_TRX'
2018-12-14T14:07:03.272552+08:00 0 [Note] Shutting down plugin 'InnoDB'
2018-12-14T14:07:03.273119+08:00 0 [Note] InnoDB: FTS optimize thread exiting.
2018-12-14T14:07:03.273566+08:00 0 [Note] InnoDB: Starting shutdown...
2018-12-14T14:08:10.771410+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-14T14:09:18.510532+08:00 0 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
2018-12-14T14:09:40.432857+08:00 0 [Note] InnoDB: MySQL has requested a very fast shutdown without flushing the InnoDB buffer pool to data files. At the next mysqld startup InnoDB will do a crash recovery!
2018-12-14T14:09:40.982834+08:00 0 [Note] InnoDB: Shutdown completed; log sequence number 0
2018-12-14T14:09:40.986140+08:00 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2018-12-14T14:09:40.986185+08:00 0 [Note] Shutting down plugin 'MEMORY'
2018-12-14T14:09:40.986196+08:00 0 [Note] Shutting down plugin 'CSV'
2018-12-14T14:09:40.986200+08:00 0 [Note] Shutting down plugin 'sha256_password'
2018-12-14T14:09:40.986203+08:00 0 [Note] Shutting down plugin 'mysql_native_password'
2018-12-14T14:09:40.986303+08:00 0 [Note] Shutting down plugin 'binlog'
2018-12-14T14:09:40.986775+08:00 0 [Note] /usr/sbin/mysqld: Shutdown complete

总结

1、在向前修改主机时间,MySQL停止时会出现hang,可能出现的大问题是数据入库时间会错乱

2、修改数据库的服务器时间,上线的系统是严禁修改的

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
关系型数据库 MySQL 网络安全
主机无法访问远程mysql服务
主机无法访问远程mysql服务
94 0
|
监控 关系型数据库 MySQL
企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库
企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库
182 1
|
SQL 监控 关系型数据库
MySQL企业版工具——使用MySQL Enterprise Monitor监控MySQL数据库和主机---发表到爱可生开源社区
MySQL在企业版里的有个工具MySQL Enterprise Monitor,可以用于监控MySQL实例和主机性能。现实验如下
1250 0
|
关系型数据库 MySQL 数据库
MySQL常见问题的解决,root用户密码忘记,不是内部或外部命令,修改数据库和表的字符编码,命令行客户端的字符集问题
MySQL常见问题的解决,root用户密码忘记,不是内部或外部命令,修改数据库和表的字符编码,命令行客户端的字符集问题
367 2
MySQL常见问题的解决,root用户密码忘记,不是内部或外部命令,修改数据库和表的字符编码,命令行客户端的字符集问题
|
关系型数据库 MySQL Linux
Centos 8系统Mysql 8修改root密码
Centos 8系统Mysql 8修改root密码
|
关系型数据库 MySQL Java
Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep linux下mysql修改连接超时wait_timeout修改后就ok了
Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep linux下mysql修改连接超时wait_timeout修改后就ok了
194 1
|
SQL 存储 数据可视化
删库跑路?不可回滚?MySQL创建和管理表,修改清空表,MySQL8新特性DDL原子化,完整详细可收藏
删库跑路?不可回滚?MySQL创建和管理表,修改清空表,MySQL8新特性DDL原子化,完整详细可收藏
329 0
删库跑路?不可回滚?MySQL创建和管理表,修改清空表,MySQL8新特性DDL原子化,完整详细可收藏
|
SQL 关系型数据库 MySQL
MySQL基础-表操作~修改数据
修改数据的具体语法为: UPDATE 表名 SET 字段名1 = 值1 , 字段名2 = 值2 , .... [ WHERE 条件 ] ;
153 0
|
存储 Ubuntu 关系型数据库
Ubuntu 18.04 修改Mysql默认数据存储路径
Ubuntu 18.04 修改Mysql默认数据存储路径
547 0
Ubuntu 18.04 修改Mysql默认数据存储路径
|
SQL 监控 关系型数据库
Intel PAUSE指令变化如何影响MySQL的性能
x86、arm指令都很多,无论是应用程序员还是数据库内核研发大多时候都不需要对这些指令深入理解,但是 Pause 指令和数据库操作太紧密了,本文通过一次非常有趣的性能优化来引入对 Pause 指令的理解,期望可以事半功倍地搞清楚 CPU指令集是如何影响你的程序的。
Intel PAUSE指令变化如何影响MySQL的性能