部署运维Java

docker安装mysql8.0

2019-10-17  本文已影响0人  黄黄丶

养成良好的记录习惯
作者:黄黄

拉取mysql镜像

(默认最新8.0以上)

docker pull mysql
docker pull mysql:版本号

创建需要挂载的目录

mkdir -p /Project/Docker/mysql/data /Project/Docker/mysql/logs /Project/Docker/mysql/conf

创建配置文件

注:挂载配置文件必须先在宿主机创建 .cnf自定义配置文件,不然无法启动

cd Project/Docker/mysql/conf
vi my.cnf

加入自定义配置


# Copyright (c) 2018, 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

# Custom config should go here
#不区分大小写配置
lower_case_table_names=1

启动容器

docker run \
-d -p 3306:3306 \
--name zzw-mysql \
-v /Project/Docker/mysql/conf:/etc/mysql/conf.d \
-v /Project/Docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root初始密码 \
-e MYSQL_USER=新用户名 \
-e MYSQL_PASSWORD=新用户密码 \
--privileged=true \
--restart=always \
mysql

登陆mysql

docker exec -it zzw-mysql bash 
mysql -u root -p

创建用户远程访问

CREATE USER 'name'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxx';

赋予全部库的全部权限给新建用户

GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'%';

重启容器

docker restart zzwmysql
上一篇下一篇

猜你喜欢

热点阅读