前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【MySQL】:MySQL 8 安装(基于 Docker)

【MySQL】:MySQL 8 安装(基于 Docker)

作者头像
WEBJ2EE
发布2022-01-24 11:05:39
2.2K0
发布2022-01-24 11:05:39
举报
文章被收录于专栏:WebJ2EE
代码语言:javascript
复制
目录
1. 安装 
2. 测试

1. 安装

搜索镜像:

代码语言:javascript
复制
docker search mysql

拉取镜像:

代码语言:javascript
复制
docker pull mysql

创建容器:

代码语言:javascript
复制
docker run --name webj2eedev-mysql \
  -v /data/webj2eedev-mysql:/var/lib/mysql \
  -p 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=webj2eedev@2022 \
  -d mysql

进入容器:

代码语言:javascript
复制
docker exec -it webj2eedev-mysql /bin/bash

登录MySQL:

代码语言:javascript
复制
mysql -uroot -pwebj2eedev@2022

切换数据库:

代码语言:javascript
复制
use mysql;

授权:

代码语言:javascript
复制
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'dareway@2022';

刷新权限:

代码语言:javascript
复制
flush privileges;

2. 测试

使用 DBEaver 连接测试一波:

3. 凑个字数

代码语言:javascript
复制
When you start the mysql image, you can adjust the configuration of the MySQL instance by passing one or more environment variables on the docker run command line. Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.

MYSQL_ROOT_PASSWORD
This variable is mandatory and specifies the password that will be set for the MySQL root superuser account. In the above example, it was set to my-secret-pw.

MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.

MYSQL_ALLOW_EMPTY_PASSWORD
This is an optional variable. Set to a non-empty value, like yes, to allow the container to be started with a blank password for the root user. NOTE: Setting this variable to yes is not recommended unless you really know what you are doing, since this will leave your MySQL instance completely unprotected, allowing anyone to gain complete superuser access.

参考:

MySQL: https://dev.mysql.com/doc/ DockerHub: https://hub.docker.com/_/mysql

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 WebJ2EE 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档