docker安装mysql并设置时区

docker安装mysql并设置时区并修改密码

#使用docker 下载mysql镜像
docker pull mysql:5.7
#启动mysql:5.7并设置密码
docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:5.7
docker restart 容器id   # 重启容器
#进入容器
docker exec -it mysql5.7(容器名) /bin/bash
#登录mysql
 mysql -u root -p
 
 #查看时区
 show variables like "%time_zone%";
#修改mysql全局时区为北京时间,即我们所在的东8区
set global time_zone = '+8:00';
#修改当前会话时区
set time_zone = '+8:00';
#立即生效
flush privileges;
[root@VM-12-8-centos oauth]# docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED        STATUS       PORTS                               NAMES
05004f246a11   mysql:5.7    "docker-entrypoint.s…"   3 months ago   Up 4 hours   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql5.7
d0f4a0e5ce16   tomcat:9.0   "catalina.sh run"        3 months ago   Up 3 weeks   8080/tcp                            amazing_shannon
[root@VM-12-8-centos oauth]# docker exec -it mysql5.7 /bin/bash
root@05004f246a11:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30113
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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 clear the current input statement.

mysql> show variables like "%time_zone%";
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | UTC    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)

mysql> set global time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)

mysql> set time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

修改mysql的密码

#1、查看容器服务
docker ps
#2、进入mysql容器
docker exec -it mysql(容器名) /bin/bash
#3、登录MySQL
mysql -u root -p
#5、修改MySQL密码
SET PASSWORD FOR 'root' = PASSWORD('密码');
#6、修改本地MySQl密码       
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('密码');
#7、退出mysql
quit
#8、ctrl+p+q退出mysql容器
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱上编程2705

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值