使用Docker安装MySql8.0效率很高。
一、下载镜像
1、 docker pull mysql8.0
二、创建文件夹
mkdir -p /usr/local/docker/mysql/conf
mkdir -p /usr/local/docker/mysql/logs
mkdir -p /usr/local/docker/mysql/data
三、定义配置文件
在conf文件夹里创建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
lower_case_table_names=1
# Custom config should go here
!includedir /etc/mysql/conf.d/
四、启动容器实例
docker run -p 3306:3306 --name mysql8 --restart=always -v /usr/local/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw -v /usr/local/docker/mysql/logs:/var/log/mysql -v/usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e TZ=Asia/Shanghai -d mysql:8.0
五、其他指令
1、启动docker
systemctl start docker
2、关闭docker
systemctl stop docker
3、重启docker
systemctl restart docker
4、查看docker运行状态
systemctl status docker
5、设置开机自启动
systemctl enable docker
6、删除镜像
删除单个镜像
docker rmi 镜像名/ID
强制删除
docker rmi -f 镜像名/ID
删除多个镜像 空格分割
docker rmi 镜像名/ID 镜像名/ID 镜像名/ID
全部删除
docker rmi -f $(docker images -qa)