栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

windows 下 docker 安装 MySQL

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

windows 下 docker 安装 MySQL

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

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

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

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

PS C:Windowssystem32> docker search mysql

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

PS I:dockerdata> docker pull mysql:latest

第三步 运行容器

PS I:dockerdata> 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 数据库

 轻松搞定

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/885194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号