本文来自于【阿里云官方镜像站:https://developer.aliyun.com/mirror/?utm_content=g_1000307095 】

原文链接:https://developer.aliyun.com/article/752820?spm=a2c6h.12873581.0.0.54c47e46mLfYep

镜像下载、域名解析、时间同步请点击阿里巴巴开源镜像站

一、下载mysql8镜像

docker pull mysql

二、创建mysql8配置文件

vi /etc/my.cnf #编辑MySQL配置文件

my.cnf文件内容

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; version 2 of the License.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA## The MySQL Server configuration file.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Custom config should go here!includedir /etc/mysql/conf.d/

三、创建mysql容器

docker run -p 60306:3306 -e MYSQL_ROOT_PASSWORD=123 -v /etc/my.cnf:/etc/mysql/my.cnf:rw -v /etc/localtime:/etc/localtime:ro --name mysql8 --restart=always -dit mysql
-p 60306:3306 #本机60306端口映射到容器3306端口-e MYSQL_ROOT_PASSWORD=123 #设置MySQL的root用户密码-v /etc/my.cnf:/etc/mysql/my.cnf:rw #本机的MySQL配置文件映射到容器的MySQL配置文件-v /etc/localtime:/etc/localtime:ro #本机时间与数据库时间同步--name mysql8 #设置容器别名--restart=always #当重启Docker时会自动启动该容器-dit mysql #后台运行并可控制台接入

四、进入mysql控制台

docker exec -it b6cfb244d0c0 bash #进入MySQL容器
mysql -uroot -p123 #进入MySQL控制台
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; #修改root用户密码

“阿里巴巴开源镜像站提供全面,高效和稳定的系统镜像、应用软件下载、域名解析和时间同步服务。”



更多相关文章

  1. [Android]查看KeyStore的MD5或SHA1签名
  2. Android(安卓)获取控件的宽和高
  3. 在 CentOS 7 操作系统进行 OpenVZ 7 安装
  4. 开发环境下载及设置(图文教程)
  5. docker是干什么的,docker常用命令
  6. 移动端布局rem+vw,grid布局
  7. Docker容器数据卷
  8. rem+vw 布局的原理与 rem 的设置技巧
  9. Docker重要容器命令

随机推荐

  1. Linux CentOS 配置Tomcat环境
  2. Linux 上samba服务的配置
  3. Linux基础知识总结
  4. linux环境下写C++操作mysql(二)
  5. Linux生成随机字符串
  6. 在VNC远程桌面环境Xfce4中Tab键失效的解
  7. Linux防火墙配置
  8. Shell脚本编写简明教程
  9. 手把手教你在ubuntu下创建桌面快捷方式
  10. 在Linux里设置用户环境变量的方法