windows 下 docker 安装 MySQL

docker技术的出现大大的降低了各种软件的安装效率和速度。

下面为2分钟在Docker 里面安装MySQL

下面所有操作都在windows powershell 下面执行

第一步:查看仓库可用版本

PS C:\Windows\system32> docker search mysql

windows 下 docker 安装 MySQL_第1张图片

第二步 拉取最新版本 MySQL镜像(当然也可以指定版本)

PS I:\docker\data> docker pull mysql:latest

windows 下 docker 安装 MySQL_第2张图片

第三步 运行容器

PS I:\docker\data> docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysql mysql

docker run --启动容器
-itd 后台运行
-name mysql-test --指定容器名称为mysql-test
-e MYSQL_ROOT_PASSWORD=mysql--配置环境变量,指定root用户的密码为mysql
-p 3306:3306  -映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL

第四步:查看是否安装成功 docker ps

第五步:MySQL密码验证参数修改及设置

先进入容器

 docker exec -it mysql-test /bin/bash

root@3e4135be5b0e:/# mysql -u root -pmysql
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 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 user,plugin from user;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

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

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.02 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

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

第六步 Navicat 连接MySQL 数据库

windows 下 docker 安装 MySQL_第3张图片

windows 下 docker 安装 MySQL_第4张图片

 轻松搞定

你可能感兴趣的:(工具,docker,容器,运维)