docker mysql

本文介绍了如何使用Docker运行MySQL容器,强调了数据卷映射的重要性以实现数据持久化,避免容器删除时数据丢失。同时,讨论了通过设置环境变量和挂载配置文件来定制MySQL实例的方法,包括设置root密码和调整字符集。此外,还提供了查看和设置MySQL启动参数的示例。
摘要由CSDN通过智能技术生成

直接简单安装

docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 
mysql

mysql-test是名字

123456 是root密码

数据卷映射

更为复杂的是将mysql的数据卷映射到宿主机上。这样不至于在mysql销毁的时候把数据也删了

docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

其中/var/lib/mysql就说mysql的数据文件夹

设置配置文件

或许我们应该更主动一些,设置配置文件。

挂载mysql容器里面的/etc/mysql/my.cnf
但请看到这个文件里面的内容

# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
#
# 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

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

它什么都没有做,只是引入了/etc/mysql/conf.d/文件夹,和/etc/mysql/mysql.conf.d/文件夹。这个两个文件夹下有一些配置文件.那里面的配置文件经过查看后,其实里面也没有什么东西
我们当然可以直接新建一个aaa.conf然后挂载到这个/etc/mysql/my.cnf

无配置自带参数

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

查看所有的参数列表如下

$ docker run -it --rm mysql:tag --verbose --help
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值