docker安装mysql执行now()函数,时差为8小时
Posted you only can live once
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker安装mysql执行now()函数,时差为8小时相关的知识,希望对你有一定的参考价值。
经过一番查询最最直接的方式是:在my.conf文件中的[mysqld]下添加
default-time-zone=Asia/Shanghai
由于mysql是通过 docker 安装的,当时配置文件采用的是挂载的方式。所以不需要进入mysql容器内修改配置。修改挂载文件就行。修改完重启容器会自动同步到mysql容器内。
查看mysql 容器挂载目录:
[root@VM-4-5-centos ~]# docker inspect mysql | grep Mounts -A 24
"Mounts": [
"Type": "bind",
"Source": "/docker/mysql/conf",
"Destination": "/etc/mysql/conf.d",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
,
"Type": "bind",
"Source": "/docker/mysql/logs",
"Destination": "/var/log/mysql",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
,
"Type": "bind",
"Source": "/docker/mysql/data",
"Destination": "/var/lib/mysql",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
根据查询可以知道挂载目录在/docker/mysql/conf下,添加并重启容器,修改成功。
mysql> select now(), curdate(), curtime();
+---------------------+------------+-----------+
| now() | curdate() | curtime() |
+---------------------+------------+-----------+
| 2023-03-29 23:40:30 | 2023-03-29 | 23:40:30 |
+---------------------+------------+-----------+
1 row in set (0.00 sec)
以上是关于docker安装mysql执行now()函数,时差为8小时的主要内容,如果未能解决你的问题,请参考以下文章
MySQL、phpMyAdmin:TIMESTAMP 始终执行 NOW 函数