直接简单安装
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