mysql docker 系统时间_docker+mysql基本搭建过程,及修改时间

修改系统时间

[root@32c64-0425445 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

或者

[root@32c64-0425445 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

或者

[root@32c64-0425445 ~]# systemctl enable ntpd

[root@32c64-0425445 ~]# systemctl start ntpd

或者

[root@32c64-0425445 ~]# timedatactl set-timezone Asia/Shanghai

若想改回UTC时间 删除/etc/localtime便可

查询镜像

[root@bms-e4e3 ~]# docker search mysql

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED

docker.io docker.io/mysql MySQL is a widely used, open-source relati... 7708[OK]

docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2530[OK]

docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 585[OK]

docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 161[OK]

docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 103docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 86[OK]

docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60[OK]

docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 48[OK]

docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 45docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 39docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 31docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 24[OK]

docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 23[OK]

docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 20[OK]

docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 18docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 12docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 9docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 8docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6docker.io docker.io/dsteinkopf/backup-all-mysql backup all DBs in a mysql server 5[OK]

docker.io docker.io/openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openz... 2

docker.io docker.io/jelastic/mysql An image of the MySQL database server main... 1docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0[OK]

docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... 0[OK]

下载镜像

//如果需要挂载以前的数据,注意下载和以前对应的版本

[root@bms-e4e3 ~]# docker inspect 旧版本镜像id

[root@bms-e4e3 ~]# docker pull mysql:5.7

运行镜像

docker run -p 3306:3306 --name mysql5.7 --restart=always -v /data/mysql/datadir:/var/lib/mysql -v /data/mysql/conf/:/etc/mysql/ -v /data/mysql/log/:/var/log/mysql/ -e MYSQL_ROOT_PASSWORD=123456 -d docker.io/mysql:5.7

命令说明:

-p 3306:3306:将容器的3306端口映射到主机的3306端口

-v $PWD/conf/my.cnf:/etc/mysql/my.cnf:将主机当前目录下的conf/my.cnf挂载到容器的/etc/mysql/my.cnf

-v $PWD/logs:/logs:将主机当前目录下的logs目录挂载到容器的/logs

-v $PWD/data:/var/lib/mysql:将主机当前目录下的data目录挂载到容器的/var/lib/mysql

-e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码

查看容器时间

[root@mysql ~]# docker exec -it mysql5.7bash

root@b6ab4d9b2869:/# dateFri May17 11:21:57 CST 2019

//如果时间不正确,则做以下操作

root@b6ab4d9b2869:/# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

或者

root@b6ab4d9b2869:/# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

root@b6ab4d9b2869:/# exit//重启mysql容器

[root@mysql ~]# docker restart mysql5.7

//再次进入容器查看容器时间和mysql时间

[root@mysql ~]# docker exec -it mysql5.7bash

root@b6ab4d9b2869:/# dateFri May17 11:26:01 CST 2019root@b6ab4d9b2869:/# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 26Server version:5.7.26-log MySQL Community Server (GPL)

Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

mysql> selectnow();+---------------------+

| now() |

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

| 2019-05-17 11:25:06 |

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

1 row in set (0.00sec)

mysql>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值