安装mysql8
设置共享目录,我设置的是F盘
配置文件my.cnf 【注意以下2行】
bind-address = 0.0.0.0
default_authentication_plugin= mysql_native_password
# 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
bind-address = 0.0.0.0
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
启动docker安装命令【如果报错可以提前将映射的目录在windows机器上创建好,注意F盘前面的"//"】:
# git bash终端
docker run \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=root \
-v //f/docker/mysql/data:/var/lib/mysql:rw \
-v //f/docker/mysql/log:/var/log/mysql:rw \
-v //f/docker/mysql/config/my.cnf:/etc/mysql/my.cnf:rw \
--name mysql8 \
--restart=always \
-d mysql
以上windows10使用git bash可能会报错,可以使用powershell启动如下命令
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -v F:/docker/mysql/data:/var/lib/mysql:rw -v F:/docker/mysql/log:/var/log/mysql:rw -v F:/docker/mysql/config/my.cnf:/etc/mysql/my.cnf:rw --name mysql8 --restart=always -d mysql
使用navicat或者其它客户端测试连接。