docker mysql 8.0.29最新版简单安装

docker mysql

一、环境准备

ubuntu 22.04 LTS

docker 20.10.15

docker pull 8.0.29

webrx@us:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy

webrx@us:~$ docker version
Client: Docker Engine - Community
 Version:           20.10.15
 API version:       1.41
 Go version:        go1.17.9
 Git commit:        fd82621
 Built:             Thu May  5 13:21:10 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.15
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.9
  Git commit:       4433bf6
  Built:            Thu May  5 13:19:15 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.4
  GitCommit:        212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
 runc:
  Version:          1.1.1
  GitCommit:        v1.1.1-0-g52de29d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

二、pull mysql

webrx@us:~$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
redis        7         734d0a06b64e   16 hours ago   411MB
mysql        8.0.29    96d0eae5ed60   12 days ago    524MB
nginx        latest    605c77e624dd   4 months ago   141MB
redis        latest    7614ae9453d1   4 months ago   113MB
mysql        5.6       dd3b2a5dcb48   4 months ago   303MB
mysql        5.6.51    dd3b2a5dcb48   4 months ago   303MB
mysql        latest    3218b38490ce   4 months ago   516MB
debian       9         c599fc96ef79   4 months ago   101MB
debian       latest    6f4986d78878   4 months ago   124MB
ubuntu       22.04     9d28ccdc1fc7   5 months ago   76.3MB
ubuntu       latest    ba6acccedd29   6 months ago   72.8MB
mysql        5.5.62    d404d78aa797   3 years ago    205MB

webrx@us:~$ docker pull mysql:8.0.29
8.0.29: Pulling from library/mysql
Digest: sha256:2dafe3f044f140ec6c07716d34f0b317b98f8e251435abd347951699f7aa3904
Status: Image is up to date for mysql:8.0.29
docker.io/library/mysql:8.0.29

三、建立容器

docker run -itd -P mysql:8.0.29

webrx@us:~$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
webrx@us:~$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
webrx@us:~$ docker run -itd -P --restart always -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=root --name mysql8029 mysql:8.0.29
dd199cfd9f0fedbfa28ec9ee8f5521ca9c0d21b89937fb5212a250dd36c5239b
webrx@us:~$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                                        NAMES
dd199cfd9f0f   mysql:8.0.29   "docker-entrypoint.s…"   5 seconds ago   Up 4 seconds   0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp   mysql8029

四、测试容器服务器

webrx@us:~$ docker run -it --rm mysql:8.0.29 mysql -h192.168.0.78 -uroot -P49154 -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 | dd199cfd9f0f | 8.0.29    | /usr/     | /var/lib/mysql/ |
+--------+--------------+-----------+-----------+-----------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29    |
+-----------+
1 row in set (0.00 sec)

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

image-20220510114848795

五、mysql容器主机配置信息

进入容器

webrx@us:~$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS       PORTS                                                                                        NAMES
dd199cfd9f0f   mysql:8.0.29   "docker-entrypoint.s…"   2 hours ago   Up 2 hours   0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp   mysql8029

webrx@us:~$ docker exec -it d /bin/bash

root@dd199cfd9f0f:/# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@dd199cfd9f0f:/# mysql --version
mysql  Ver 8.0.29 for Linux on x86_64 (MySQL Community Server - GPL)
root@dd199cfd9f0f:/# whereis mysqld
mysqld: /usr/sbin/mysqld
root@dd199cfd9f0f:/# 

基本的配置文件/etc/mysql/my.cnf

/etc/mysql/mysql.d/目录

root@dd199cfd9f0f:/# ls /etc/mysql
conf.d  my.cnf  my.cnf.fallback
root@dd199cfd9f0f:/# ls /etc/mysql/conf.d
docker.cnf  mysql.cnf
root@dd199cfd9f0f:/# cat /etc/mysql/my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/
root@dd199cfd9f0f:/# 

数据库目录 /var/lib/mysql

root@dd199cfd9f0f:/etc/mysql# ls /var/lib/mysql
'#ib_16384_0.dblwr'   binlog.000001   ca.pem            dd199cfd9f0f.err   ibdata1     performance_schema   server-key.pem
'#ib_16384_1.dblwr'   binlog.000002   client-cert.pem   ib_buffer_pool     ibtmp1      private_key.pem      sys
'#innodb_temp'        binlog.index    client-key.pem    ib_logfile0        mysql       public_key.pem       undo_001
 auto.cnf             ca-key.pem      db                ib_logfile1        mysql.ibd   server-cert.pem      undo_002
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值