CentOS7下使用Docker安装MySQL

本文作为一次服务器部署mysql安装过程的记录,内容可能会有缺少,敬请谅解。

服务器上需安装docker。

docker search mysql

查看所有可用版本

输出:

NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                          MySQL is a widely used, open-source relation…   12575     [OK]       
mariadb                        MariaDB Server is a high performing open sou…   4834      [OK]       
percona                        Percona Server is a fork of the MySQL relati…   576       [OK]       
phpmyadmin                     phpMyAdmin - A web interface for MySQL and M…   538       [OK]       
bitnami/mysql                  Bitnami MySQL Docker Image                      71                   [OK]
linuxserver/mysql-workbench                                                    36                   
linuxserver/mysql              A Mysql container, brought to you by LinuxSe…   35                   
ubuntu/mysql                   MySQL open source fast, stable, multi-thread…   33                   
circleci/mysql                 MySQL is a widely used, open-source relation…   25                   
google/mysql                   MySQL server for Google Compute Engine          21                   [OK]
vmware/harbor-db               Mysql container for Harbor                      10                   
rapidfort/mysql                RapidFort optimized, hardened image for mysql   9                    
bitnami/mysqld-exporter                                                        3                    
ibmcom/mysql-s390x             Docker image for mysql-s390x                    2                    
newrelic/mysql-plugin          New Relic Plugin for monitoring MySQL databa…   1                    [OK]
vitess/mysqlctld               vitess/mysqlctld                                1                    [OK]
nasqueron/mysql                                                                1                    [OK]
docksal/mysql                  MySQL service images for Docksal - https://d…   0                    
silintl/mysql-backup-restore   Simple docker image to perform mysql backups…   0                    [OK]
drud/mysql-local-57            ddev mysql local container                      0                    
drud/mysql                                                                     0                    
drud/mysql-docker-local-57     This repo has been deprecated, new tags are …   0                    
drud/mysql-docker-local        docker containers for local womysql rk          0                    [OK]
mirantis/mysql                                                                 0                    
cimg/mysql                                                                     0                    

选择支持centos7版本的mysql57:

docker pull centos/mysql-57-centos7

列出本地镜像:

docker images

运行mysql57:

docker run -p 3306:3306 --name mysql57 -e MYSQL_ROOT_PASSWORD=123456 -d centos/mysql-57-centos7

-e 似乎是指定了容器环境变量里面的MYSQL_ROOT_PASSWORD初始值为123456,但是登陆时并没有输入密码即可登录。

查看本地运行的容器:

docker ps

输出:

CONTAINER ID   IMAGE                     COMMAND                  CREATED         STATUS         PORTS                                                                                                                                       NAMES
9d7735ad255b   centos/mysql-57-centos7   "container-entrypoin…"   5 seconds ago   Up 4 seconds   0.0.0.0:3306->3306/tcp                                                                                                                      mysql57
9f1059c93395   rabbitmq:management       "docker-entrypoint.s…"   2 months ago    Up 2 months    0.0.0.0:4369->4369/tcp, 0.0.0.0:5671-5672->5671-5672/tcp, 0.0.0.0:15671-15672->15671-15672/tcp, 0.0.0.0:25672->25672/tcp, 15691-15692/tcp   rabbitmq
7bbd1b61721f   redis                     "docker-entrypoint.s…"   2 months ago    Up 2 months    0.0.0.0:6379->6379/tcp                                                                                                                      redis

mysql57的为9d7735ad255b,记录一下

进入容器:

docker exec -it 9d7735ad255b bash

修改初始密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

输出:

Query OK, 0 rows affected (0.00 sec)

修改成功。

因为本容器被放置在云服务器上,在本地的电脑上连接需要设置mysql数据库的root用户允许远程连接。

grant all privileges on *.* to 'root'@'%' identified by '你的密码';

刷新权限:

flush privileges;

测试是否能够链接:

CentOS7下使用Docker安装MySQL_第1张图片

设置最大连接数:

set GLOBAL max_connections=1000;

你可能感兴趣的:(mysql,docker,数据库)