集团网站信息建设情况,如何查询网站历史快照,注册页面设计代码,安徽建设工程信息平台前言 
和朋友一起搞一个项目#xff0c;分了一下工作#xff0c;但是mysql迟迟安装不上#xff0c;程序都在一个环境里确实容易出现很多问题#xff0c;浪费时间和经历在这些配置上#xff0c;好在有docker了#xff0c;就在docker里搭建一个Mysql数据库使用吧#xff0…前言 
和朋友一起搞一个项目分了一下工作但是mysql迟迟安装不上程序都在一个环境里确实容易出现很多问题浪费时间和经历在这些配置上好在有docker了就在docker里搭建一个Mysql数据库使用吧顺便出一篇教程记录和分享。 Linux中使用Docker部署Mysql数据库前言1 检查docker是否运行2 检索mysql镜像3 下载mysql镜像下载好后可以检查是否已经下载成功4 使用docker启动mysql数据库容器5 查看是否启动mysql数据库成功6 设置mysql数据库的远程链接进入mysql容器登陆mysql数据库授权重新授权表退出mysql退出容器7 Navicat远程链接1 检查docker是否运行 systemctl status docker k17gc10Z ~]# systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: enabled)Active: active (running) since Thu 2023-02-23 10:48:05 CST; 23h agoDocs: https://docs.docker.comMain PID: 735685 (dockerd)Tasks: 19Memory: 119.3MCGroup: /system.slice/docker.service├─735685 /usr/bin/dockerd -H fd:// --containerd/run/containerd/containerd.sock├─752356 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8081 -container-ip 172.17.0.2 -container-port 8080└─752360 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8081 -container-ip 172.17.0.2 -container-port 8080
....................... 
若没有运行则启动docker: systemctl start docker 2 检索mysql镜像 docker search mysql k17gc10Z ~]# docker search mysql
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                           MySQL is a widely used, open-source relation…   13847     [OK]       
mariadb                         MariaDB Server is a high performing open sou…   5281      [OK]       
percona                         Percona Server is a fork of the MySQL relati…   599       [OK]       
phpmyadmin                      phpMyAdmin - A web interface for MySQL and M…   744       [OK]       
circleci/mysql                  MySQL is a widely used, open-source relation…   28                   
bitnami/mysql                   Bitnami MySQL Docker Image                      80                   [OK]
bitnami/mysqld-exporter                                                         4                    
ubuntu/mysql                    MySQL open source fast, stable, multi-thread…   41                   
cimg/mysql                                                                      0                    
rapidfort/mysql                 RapidFort optimized, hardened image for MySQL   14                   
google/mysql                    MySQL server for Google Compute Engine          23                   [OK]
ibmcom/mysql-s390x              Docker image for mysql-s390x                    2                    
rapidfort/mysql8-ib             RapidFort optimized, hardened image for MySQ…   0                    
hashicorp/mysql-portworx-demo                                                   0                    
newrelic/mysql-plugin           New Relic Plugin for monitoring MySQL databa…   1                    [OK]
rapidfort/mysql-official        RapidFort optimized, hardened image for MySQ…   0                    
databack/mysql-backup           Back up mysql databases to... anywhere!         81                   
linuxserver/mysql               A Mysql container, brought to you by LinuxSe…   38                   
mirantis/mysql                                                                  0                    
docksal/mysql                   MySQL service images for Docksal - https://d…   0                    
vitess/mysqlctld                vitess/mysqlctld                                1                    [OK]
linuxserver/mysql-workbench                                                     48                   
eclipse/mysql                   Mysql 5.7, curl, rsync                          0                    [OK]
drud/mysql                                                                      0                    
silintl/mysql-backup-restore    Simple docker image to perform mysql backups…   0                    [OK] 
NAME:镜像名
DESCRIPTION说明
STARS:热度
OFFICIAL是否官方
AUTOMATED是否自动 
3 下载mysql镜像 docker pull mysql:5.7 1k17gc10Z ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
e048d0a38742: Pull complete 
c7847c8a41cb: Pull complete 
351a550f260d: Pull complete 
8ce196d9d34f: Pull complete 
17febb6f2030: Pull complete 
d4e426841fb4: Pull complete 
fda41038b9f8: Pull complete 
f47aac56b41b: Pull complete 
a4a90c369737: Pull complete 
97091252395b: Pull complete 
84fac29d61e9: Pull complete 
Digest: sha256:8cf035b14977b26f4a47d98e85949a7dd35e641f88fc24aa4b466b36beecf9d6
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7 
下载好后可以检查是否已经下载成功 docker images 17gc10Z ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
jenkins/jenkins   lts       f16216f97fcb   2 weeks ago     467MB
mysql             5.7       be16cf2d832a   3 weeks ago     455MB
hello-world       latest    feb5d9fea6a5   17 months ago   13.3kB 
REPOSITORY:镜像名
TAG:标签latest表示为最新的
IMAGE ID:镜像id
CREATED:创建时间
SIZE:大小
上图中表示mysql镜像文件已经下载成功4 使用docker启动mysql数据库容器 docker run --name mysql -e MYSQL_ROOT_PASSWORDroot -p 3306:3306 -d mysql:5.7 k17gc10Z ~]# docker run --name mysql -e MYSQL_ROOT_PASSWORDroot -p 3306:3306 -d mysql:5.7
68b7dc6f81b01f3c209a66b519633d1a6e8849bb99036fff951dddde83bd3472 
-v :指明挂在卷
–restart:自动重启
–name:给容器命名
-e:设置账号密码
-p: 指明宿主机端口docker内部端口
-d:指明用什么镜像的id启动
c5244d16078bb224ce77c3e6446ab6466a95d5fe801b2269d4c00b0eb0d65319启动的mysql容器的id5 查看是否启动mysql数据库成功 docker ps -l 7gc10Z ~]# docker ps -l
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
68b7dc6f81b0   mysql:5.7   docker-entrypoint.s…   39 seconds ago   Up 38 seconds   0.0.0.0:3306-3306/tcp, :::3306-3306/tcp, 33060/tcp   mysql 
CONTAINER ID:容器id
IMAGES镜像id
CREATED:创建时间
STATUS:状态
NAME:容器名
到此可知mysql容器创建成功 
6 设置mysql数据库的远程链接 
进入mysql容器 docker exec -it mysql bash 7gc10Z ~]# docker exec -it mysql bash 
登陆mysql数据库 mysql -u root -proot bash-4.2# mysql -u root -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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. 
授权 GRANT ALL PRIVILEGES ON . TO ‘root’‘%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION; mysql GRANT ALL PRIVILEGES ON *.* TO root% IDENTIFIED BY root WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec) 
重新授权表 FLUSH PRIVILEGES; mysql FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec) 
退出mysql exit mysql exit
Bye 
退出容器 exit bash-4.2# exit
exit 
7 Navicat远程链接