docker mysql5.6.51简单安装 SQLog链接
一、环境准备
ubuntu 22.04 LTS
docker 20.10.15
下载mysql 5.6.51
summer@us:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy
summer@us:~$ docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:47:47 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:45:38 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
二、拉取
docker pull mysql:5.6.51
三、建立容器
docker run -itdP -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=123 --name m5651 mysql:5.6.51
四、SQLog链接
SELECT @@hostname,@@port,@@version,@@basedir,@@datadir,NOW();
五、建立mysql客户端容器
-h代表连接的主机ip -p代表密码 -u代表账号 -P代表端口号 --rm代表一次性容器
#mysql:5.6.51 也可写成镜像id
summer@us:~$ docker run -it --rm mysql:5.6.51 mysql -h192.168.1.112 -uroot -p -P49185
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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 clear the current input statement.
mysql>
六、mysql修改密码
summer@us:~$ docker rm -f $(docker ps -aq)
dccb331845be
c304e1c76be9
summer@us:~$ docker run -itd -P -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=root --name m5651 dd
58c2a34c2f28d094155fe640137300901e6327afc2af9737504448a5290bd985
summer@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58c2a34c2f28 dd "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:49189->3306/tcp, :::49189->3306/tcp m5651
summer@us:~$ docker run -it mysql:5.6.51 mysql -h192.168.1.112 -uroot -p -P49189
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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 clear the current input statement.
mysql> set password = password('123');
Query OK, 0 rows affected (0.00 sec)
mysql>