一、首先安装docker
这一步自己搜~~
二、使用docker安装mysql5.7镜像
sudo docker image pull mysql:5.7.30
安装好以后使用代码查看是否安装成功
sudo docker image ls
三、在本地创建下面的文件夹
文件夹:
/home/你的用户名/mysql/data
配置文件:
/home/你的用户名/msql/mysql.conf.d/mysqld.cnf
配置文件内容:
opyright (c) 2014, 2016, 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, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
四、启动镜像
sudo docker run --name mysql -e MYSQL_ROOT_PASSWORD=123 -p 3306:3306 -d --network=host -v /home/jasper/mysql/data:/var/lib/mysql -v /home/jasper/mysql/mysql.conf.d:/etc/mysql/mysql.conf.d mysql:5.7.30
-v 你本地的文件路径(需要映射到的路径):docker中的路径
-e 设置密码
-p 设置映射端口,可以使用3307:3306
--name: 你自定义的容器名称
五、进入容器启动mysql
sudo docker exec -it mysql /bin/bash
mysql -uroot -p
六、赋予权限(方便主机下的远程连接)
grant all privileges on *.* to 'root'@'%' ;
flush privileges; 刷新权限
七、通过navicat连接
端口号,ip地址,账号密码不用我教你了吧~