5

Mariadb(mysql)如何修改默认时区及在docker中运行的配置方法

 1 year ago
source link: https://vps.la/2023/05/08/mariadbmysql%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e9%bb%98%e8%ae%a4%e6%97%b6%e5%8c%ba%e5%8f%8a%e5%9c%a8docker%e4%b8%ad%e8%bf%90%e8%a1%8c%e7%9a%84%e9%85%8d%e7%bd%ae%e6%96%b9%e6%b3%95/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

查看时区和当前时间

show variables like "%time_zone%";
select now();

临时修改时区

set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区
set time_zone = '+8:00'; ##修改当前会话时区
flush privileges; #立即生效

在/etc/my.cnf的[mysqld]区域中加上,重启mysql使新时区生效

#vim /etc/my.cnf 
default-time_zone = '+8:00'
#systemctl restart mysql

在docker中运行

如果mariadb(mysql)是在docker中运行,本来想用-e参数方式注入参数,却发现并不能生效,于是找到了docker的时区配置命令。
在宿主机上运行,进入控制台

#进入控制台
docker exec -it mariadb /bin/bash 
#修改默认时区,根据提示选择区域和城市
#dpkg-reconfigure tzdata
#需要重新启动
docker restart mariadb

未经允许不得转载:VPS啦 » Mariadb(mysql)如何修改默认时区及在docker中运行的配置方法


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK