zoukankan      html  css  js  c++  java
  • docker安装mysql

      笔记还是靠勤啊...最近部署mysql遇到这么一个问题,运行起容器以后用navicat进行连接发现连接不上,试了好几遍都没有成功,最后还是在博问里别人给出了答案。

      错误原因看这里:https://www.cnblogs.com/zhurong/p/9898675.html

      解决方案:https://www.cnblogs.com/badtree/articles/10130695.html


      但是我还是用自己的语言记录一下操作步骤。

      1.docker pull mysql 

      2.创建文件夹和my.cnf文件,文件路径如下:

      /home/data/mysql/data   (用于存放数据文件)

      /home/data/mysql/conf.d

      /home/data/mysql/conf.d/my.cnf

      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 risks
    symbolic-links=0
    
    # Custom config should go here
    !includedir /etc/mysql/conf.d/
    
    default_authentication_plugin= mysql_native_password

      3.运行容器。

      docker run --name mysql
      --restart=always
      -p 3306:3306
      -v /home/data/mysql/conf.d:/etc/mysql/conf.d
      -v /home/data/mysql/data:/var/lib/mysql
      -e MYSQL_ROOT_PASSWORD=123456
      -d mysql

      4.进入容器:docker exec -it mysql /bin/sh

         键入命令:mysql -uroot -p (如果这个时候提示Enter Password,输入123456即可)

         执行命令:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

      这个时候再用navicat进行连接就会提示连接成功了!

      

      

  • 相关阅读:
    mac上命令行解压rar
    Mac上安装PHP、Apache、MySQL
    8款不错的 CI/CD工具
    Apache 强制Http跳转Https
    使用MySQL的mysqldump命令备份数据库和把数据库备份文件恢复
    MySQL主从复制和读写分离
    Nginx参数调优
    【原创】深入理解Docker容器和镜像 -- 分析了docker的命令含义
    Elasticsearch使用备忘
    通过HTTP RESTful API 操作elasticsearch搜索数据
  • 原文地址:https://www.cnblogs.com/sunshine-wy/p/11986385.html
Copyright © 2011-2022 走看看