docker安装mysql8.0

作者: 黄黄丶 | 来源:发表于2019-10-17 20:11 被阅读0次

养成良好的记录习惯
作者:黄黄

拉取mysql镜像

(默认最新8.0以上)

docker pull mysql
docker pull mysql:版本号

创建需要挂载的目录

mkdir -p /Project/Docker/mysql/data /Project/Docker/mysql/logs /Project/Docker/mysql/conf

创建配置文件

注:挂载配置文件必须先在宿主机创建 .cnf自定义配置文件,不然无法启动

cd Project/Docker/mysql/conf
vi my.cnf

加入自定义配置


# Copyright (c) 2018, 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 risks
symbolic-links=0

# Custom config should go here
#不区分大小写配置
lower_case_table_names=1

启动容器

docker run \
-d -p 3306:3306 \
--name zzw-mysql \
-v /Project/Docker/mysql/conf:/etc/mysql/conf.d \
-v /Project/Docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root初始密码 \
-e MYSQL_USER=新用户名 \
-e MYSQL_PASSWORD=新用户密码 \
--privileged=true \
--restart=always \
mysql
  • -d 后台运行
  • -v 挂在对应数据到容器中
  • -e 指定参数 举例:
    //-e MYSQL_USER="新用户名"
    //-e MYSQL_PASSWORD="新密码" \
  • --privileged=true linux安全授权
  • --restart 服务异常后自动启动

登陆mysql

docker exec -it zzw-mysql bash 
mysql -u root -p

创建用户远程访问

CREATE USER 'name'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxx';

赋予全部库的全部权限给新建用户

GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'%';

重启容器

docker restart zzwmysql

相关文章

  • 九、docker安装mysql8.0

    docker安装mysql8.0

  • docker安装mysql8.0

    docker安装mysql8.0 1、查看可用的 MySQL 版本 访问 MySQL 镜像库地址:https://...

  • Docker 安装 MySQL8.0

    环境: centos 7.5 docker 19.03.12 MySQL8.0 docker仓库搜索MySQL...

  • docker安装mysql8.0

    养成良好的记录习惯 时间:2019年10月12日作者:黄黄邮箱:15797683468@163.com(可指出问题...

  • docker安装mysql8.0

    mysql5.7 安装在最后 指定mysql密码 自动生成密码.也可以手动指定 安装 mysql8.0 ​查看My...

  • docker安装mysql8.0

    指定mysql密码 自动生成密码.也可以手动指定 安装 mysql 安装8.0 安装5.7(没测试,应该问题不大)...

  • docker 安装mysql8.0

    拉取镜像 https://hub.docker.com/_/mysql?tab=tags&page=1&order...

  • docker 安装mysql8.0

    参考docker目录下的文章

  • 使用Docker安装MySQL8.0

    1、安装docker 2、拉取MySQL的镜像 运行完以上命令之后,镜像就已经下载下来了 3、查看镜像情况 可以看...

  • 使用Docker安装MySQL8.0

    在阿里云弄了台优惠版的服务器,打算用docker安装MySQL8.0机器是Ubuntu16.04的操作系统 1、安...

网友评论

    本文标题:docker安装mysql8.0

    本文链接:https://www.haomeiwen.com/subject/japvmctx.html