栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker安装mysql并设置时区

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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容器
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/838630.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号