Docker安装Mariadb数据库 设置root密码 图文教程

前面我们介绍了Docker的内容:

下面我们记录一下如何安装Mariadb/MySQL数据库。

镜像库搜索安装Mariadb

搜索Mariadb

$ search
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mariadb MariaDB is a community-developed fork of MyS… 2848 [OK]
bitnami/mariadb Bitnami MariaDB Docker Image 98 [OK]
linuxserver/mariadb A Mariadb container, brought to you by Linux… 75
toughiq/mariadb-cluster Dockerized Automated MariaDB Galera Cluster … 38 [OK]
colinmollenhour/mariadb-galera-swarm MariaDb w/ Galera Cluster, DNS-based service… 26 [OK]
panubo/mariadb-galera MariaDB Galera Cluster 23 [OK]
lsioarmhf/mariadb ARMHF based Linuxserver.io image of mariadb 18
million12/mariadb MariaDB 10 – ~60Mb Alpine UTF-8 16 [OK]
webhippie/mariadb Docker images for MariaDB 15 [OK]
bianjp/mariadb-alpine Lightweight MariaDB docker image with Alpine… 9 [OK]
mariadb/server MariaDB Server is a modern database for mode… 9 [OK]
centos/mariadb-101-centos7 MariaDB 10.1 SQL database server 9
severalnines/mariadb A homogeneous MariaDB Galera Cluster image t… 7 [OK]
centos/mariadb-102-centos7 MariaDB 10.2 SQL database server 5
wodby/mariadb Alpine-based MariaDB container image with or… 4 [OK]
tutum/mariadb Base docker image to run a MariaDB database … 4
circleci/mariadb CircleCI images for MariaDB 3 [OK]
rightctrl/mariadb Mariadb with Galera support 2 [OK]
jonbaldie/mariadb Fast, simple, and lightweight MariaDB Docker… 2 [OK]
kitpages/mariadb-galera MariaDB with Galera 2 [OK]
tiredofit/mariadb-backup MariaDB Backup image to backup MariaDB/… 1 [OK]
demyx/mariadb FROM webhippie/mariadb:latest 0
jelastic/mariadb An image of the MariaDB SQL database server … 0
ansibleplaybookbundle/mariadb-apb An APB which deploys RHSCL MariaDB 0 [OK]
alvistack/mariadb Docker Image Packaging for MariaDB 0 [OK]

安装Mariadb

docker pull mariadb

运行 Mariadb 镜像

运行Mariadb服务

docker run --name jmariadb -p 3306:3306 -d  -e MYSQL_ROOT_PASSWORD=jiloc mariadb
  • -e MYSQL_ROOT_PASSWORD 设置数据库root密码 jiloc
  • --name 设置容器别名

============以下是配置Mariadb的config文件映射============

查看容器ID

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c63468060135 mariadb “docker-entrypoint.s…” 34 seconds ago Exited (1) 33 seconds ago jmariadb
c948b4856671 nginx “nginx -g ‘daemon of…” 21 minutes ago Up 20 minutes 0.0.0.0:8081->80/tcp jnginx
d593465ab743 bitnami/php-fpm “php-fpm -F –pid /o…” About an hour ago Up About an hour 9000/tcp jphp-fpm

创建配置文件夹/文件,挂载数据

创建 D:\DockerConfig\mysql ,我们将这个文件夹作为一会Docker将要映射的文件位置。

docker run -d -p 3306:3306 --name mariadb -v D:\DockerConfig\mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=jiloc mariadb

测试连接

docker ps -a

确认数据库实例在运行,然后我们这里使用Navicat Premium 进行连接

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr月付$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快注册即送$50点击购买】!

腾讯云爆款1C1G云服务器首年99元

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

发表评论

电子邮件地址不会被公开。 必填项已用*标注