Docker | Mysql 挂载目录一键部署
创建挂载文件
mkdir -p conf
mkdir -p logs
mkdir -p mysql
编辑配置文件
cd conf/
vi my.cnf
# Copyright (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 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
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections = 2000
max_user_connections = 1900
max_connect_errors = 100000
max_allowed_packet = 50M
lower_case_table_names=1
[mysqld]
skip-name-resolve
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#保存后退出
启动
docker命令直接启动
$ docker run -p 3306:3306 --name mysql5.7 -v my.cnf:/etc/mysql/my.cnf -v logs:/logs -v mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker-compose启动
# docker-compose.yml
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql5.7
ports:
- "3306:3306"
environment:
- "MYSQL_ROOT_PASSWORD=123456"
volumes:
- ./conf/my.cnf:/etc/mysql/my.cnf
- ./logs:/logs
- ./mysql:/var/lib/mysql
$ docker-compose -f docker-compose.yml up -d
--完--
- 原文作者: 留白
- 原文链接: https://zfunnily.github.io/2023/11/mysql/
- 更新时间:2024-04-16 01:01:05
- 本文声明:转载请标记原文作者及链接