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容器