docker mysql
一、环境准备
ubuntu 22.04 LTS
docker 20.10.15
下载mysql 8.0.29
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:8.0.29
三、建立容器
docker run -itd -P --restart always -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=root --name mysql80291 mysql:8.0.29
四、测试容器
summer@us:~$ docker run -it --rm mysql:8.0.29 mysql -h192.168.1.112 -uroot -P49184 -p
summer@us:~$ docker run -it --rm mysql:8.0.29 mysql -h192.168.1.112 -uroot -P49184 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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> select @@port,@@hostname,@@version,@@basedir,@@datadir;
+--------+--------------+-----------+-----------+-----------------+
| @@port | @@hostname | @@version | @@basedir | @@datadir |
+--------+--------------+-----------+-----------+-----------------+
| 3306 | c76b80119f17 | 8.0.29 | /usr/ | /var/lib/mysql/ |
+--------+--------------+-----------+-----------+-----------------+
1 row in set (0.00 sec)
mysql>
五、mysql容器主机配置信息
进入容器
summer@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c76b80119f17 mysql:8.0.29 "docker-entrypoint.s…" 36 minutes ago Up 36 minutes 0.0.0.0:49184->3306/tcp, :::49184->3306/tcp, 0.0.0.0:49183->33060/tcp, :::49183->33060/tcp mysql80291
summer@us:~$ docker exec -it c /bin/bash
root@c76b80119f17:/#
基本配置文件/etc/mysql/my.cnf
/etc/mysql/mysql.d/目录
数据库目录/var/lib/mysql
summer@us:~$ docker exec -it c /bin/bash
root@c76b80119f17:/# ls /var/lib/mysql
'#ib_16384_0.dblwr' auto.cnf binlog.index ca.pem ib_buffer_pool ibdata1 mysql.ibd public_key.pem sys
'#ib_16384_1.dblwr' binlog.000001 c76b80119f17.err client-cert.pem ib_logfile0 ibtmp1 performance_schema server-cert.pem undo_001
'#innodb_temp' binlog.000002 ca-key.pem client-key.pem ib_logfile1 mysql private_key.pem server-key.pem undo_002
root@c76b80119f17:/#