docker 安装mysql-server

################

查找mysql-server镜像:docker search mysql-server

[root@igoodful ~]# docker search mysql-server
INDEX       NAME                                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql/mysql-server            Optimized MySQL Server Docker images. Crea...   989                  [OK]
docker.io   docker.io/kdedesign/mysql-server        Armhf version docker image of MySQL Commun...   3                    
docker.io   docker.io/ruwen/mysql-server-5.1        MySQL server 5.1. For local development, d...   3                    [OK]
docker.io   docker.io/dockeradminnet/mysql-server                                                   1                    
docker.io   docker.io/dshatohin/mysql-servercore    Production ready 👌                              1                    
docker.io   docker.io/igaguri/mysql-server-utf8     mysql/mysql-serverを日本語対応                        1                    [OK]
docker.io   docker.io/lsdriscoll/mysql-server-5.0   MySQL 5.0                                       1                    [OK]
docker.io   docker.io/aaqibfaizi/mysql-server-56                                                    0                    
docker.io   docker.io/abhivelotio/mysql-server                                                      0                    
docker.io   docker.io/abiskop/mysql-server                                                          0                    [OK]
docker.io   docker.io/akkojima/mysql-server                                                         0                    
docker.io   docker.io/barnybug/mysql-server         Minimal MySQL server (5.5.35)                   0                    
docker.io   docker.io/chandra4944/mysql-server                                                      0                    
docker.io   docker.io/epages/mysql-server                                                           0                    
docker.io   docker.io/hidetarou2013/mysql-server    mysql-server                                    0                    [OK]
docker.io   docker.io/iocvnpt/mysql-server                                                          0                    
docker.io   docker.io/jabakir/mysql-server                                                          0                    
docker.io   docker.io/juhu2/mysql-server            centos with mysql-server                        0                    
docker.io   docker.io/leios76/mysql-server          mysql-server                                    0                    [OK]
docker.io   docker.io/ofthesun9/mysql-server                                                        0                    
docker.io   docker.io/rumatakira/mysql-server       Just taged form mysql/mysql-server:5.7 for...   0                    
docker.io   docker.io/tcpcloud/mysql-server                                                         0                    
docker.io   docker.io/urlos/mysql-server                                                            0                    
docker.io   docker.io/zhaotq/mysql-server                                                           0                    
docker.io   docker.io/zhonghl003/mysql-server                                                       0                    
[root@igoodful ~]# docker pull mysql/mysql-server:latest

 

拉取mysql-server镜像:docker pull mysql/mysql-server:latest

[root@igoodful ~]# docker pull mysql/mysql-server:latest
Trying to pull repository docker.io/mysql/mysql-server ... 
latest: Pulling from docker.io/mysql/mysql-server
6a4a3ef82cdc: Pull complete 
5518b09b1089: Pull complete 
b6b576315b62: Pull complete 
349b52643cc3: Pull complete 
abe8d2406c31: Pull complete 
c7668948e14a: Pull complete 
c7e93886e496: Pull complete 
Digest: sha256:d6c8301b7834c5b9c2b733b10b7e630f441af7bc917c74dba379f24eeeb6a313
Status: Downloaded newer image for docker.io/mysql/mysql-server:latest
[root@igoodful ~]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql/mysql-server   latest              1d9c2219ff69        4 months ago        496 MB
[root@igoodful ~]# docker images -a
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql/mysql-server   latest              1d9c2219ff69        4 months ago        496 MB

 

运行容器:docker run -itd

[root@igoodful ~]# docker run -itd --name mysql_3306 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456abcABC docker.io/mysql/mysql-server
96530bae3777352a89b017c15ff39f61993fcfc95cce247ebb7cfd68b6ca9475
[root@igoodful ~]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS                            PORTS                                     NAMES
96530bae3777        docker.io/mysql/mysql-server   "/entrypoint.sh my..."   5 seconds ago       Up 4 seconds (health: starting)   0.0.0.0:3306->3306/tcp, 33060-33061/tcp   mysql_3306
[root@igoodful ~]# mysql

进入容器:docker exec -it mysql_3306 bash

[root@igoodful ~]# docker exec -it mysql_3306  bash
bash-4.4# ls
bin  boot  dev    docker-entrypoint-initdb.d  entrypoint.sh  etc    healthcheck.sh    home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
bash-4.4# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

 

登录mysql-server

bash-4.4# mysql -uroot -p123456abcABC 
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 38
Server version: 8.0.32 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.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.03 sec)

mysql> show global variables like '%char%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.00 sec)

mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> show create database test;
+----------+--------------------------------------------------------------------------------------------------------------------------------+
| Database | Create Database                                                                                                                |
+----------+--------------------------------------------------------------------------------------------------------------------------------+
| test     | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */ |
+----------+--------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> exit;
Bye
bash-4.4# exit;
exit
[root@igoodful ~]# history 

 

 

 

 

 

 

 

 

#########################

 
posted @ 2023-06-14 15:42  igoodful  阅读(77)  评论(0编辑  收藏  举报