mysql 5.7 dockfile_MySQL5.7.22 编译安装Dockfile

本文详细介绍了如何在CentOS 7环境中使用Docker构建并运行MySQL 5.7.22。首先,通过Dockerfile构建包含Java 1.8的CentOS基础镜像。接着,提供了Dockerfile和my.cnf文件内容,用于编译安装MySQL 5.7.22,并设置了必要的配置参数。最后,演示了启动容器、初始化数据库、设置和授权root用户的步骤。
摘要由CSDN通过智能技术生成

编写不易,转载请注明 (http://shihlei.iteye.com/blog/2423672)

一 Java1.8 Dockerfile 构建(可以省略)

(1)目录结构

$ ls

Dockerfile jdk-8u161-linux-x64.tar.gz

(2)Dockerfile

############################################################

# Dockerfile to build Java Installed Containers

# Based on Centos Latest

# docker build -t centos:java .

############################################################

FROM centos:latest

LABEL author="puppet" \

description="Dockerfile to build Java Installed Containers"

# ADD JDK

ADD jdk-8u161-linux-x64.tar.gz /usr/local/

RUN /bin/bash -c 'cd /usr/local; ln -s jdk1.8.0_161 java'

ENV JAVA_HOME=/usr/local/java

ENV JRE_HOME=$JAVA_HOME/jre \

PATH=$JAVA_HOME/bin:$PATH \

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOEM/lib/tools.jar

(3)构建: docker build -t centos:java .

二 mysql 5.7.22 Dockerfile

(1)目录结构

$ ls

Dockerfile my.cnf mysql-boost-5.7.22.tar.gz

(2)my.cnf

[mysqld]

datadir=/data/mysql/mysql_data

socket=/data/mysql/mysql_data/mysql.sock

user=mysql

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

key_buffer_size = 8144M

table_cache_size = 1024M

read_buffer_size = 128M

sort_buffer_size = 32M

query_cache_size = 100M

thread_cache_size = 16

thread_concurrency = 32

max_heap_table_size = 400M

tmp_table_size = 400M

max_connections = 500

# The end

(2)Dockerfile

############################################################

# Dockerfile to build MySQL 5.7.22 on CentOS7

# Based on Centos Latest

# docker build -t puppet:mysql .

############################################################

FROM centos:java

LABEL author="puppet" \

description="Dockerfile to build MySQL 5.7.22 on Centos 7"

# add MySQL, download source code

ADD mysql-boost-5.7.22.tar.gz /usr/local/mysql

# add group , user;

RUN /bin/bash -c 'groupadd mysql; useradd -r -g mysql -s /bin/false mysql'

# workdir

WORKDIR /usr/local/mysql/mysql-5.7.22

# mkdir dir;

RUN /bin/bash -c 'mkdir -p /data/mysql/mysql_data ; chown -R mysql:mysql /data/mysql'

# install dependency;

RUN /bin/bash -c 'yum -y install bison cmake make gcc gcc-c++ ncurses-devel'

# make

RUN /bin/bash -c 'cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/mysql-5.7.22 -DMYSQL_DATADIR=/data/mysql/mysql_data -DMYSQL_UNIX_ADDR=/usr/local/mysql/5.7.22/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost/boost_1_59_0/ ; make ; make install'

# set start

RUN /bin/bash -c 'cp ./support-files/mysql.server /etc/init.d/mysqld; chown -R mysql:mysql /usr/local/mysql/; chmod 755 /etc/init.d/mysqld; chkconfig --add mysqld; chkconfig mysqld on'

# add conf

ADD my.cnf /etc/

# port 3306

EXPOSE 3306:3306

(3)构建: docker build -t centos:java .

三 使用

(1)启动容器

docker run -tid --net shadownet --ip 6.6.6.10 --hostname mysql --name mysql -p 3306:3306 -v /Users/mysql/data_share:/data/mysql_share --volumes-from datashare puppet:mysql /bin/bash

docker exec -ti mysql /bin/bash

(2)初始化数据库,连接

cd /usr/local/mysql/mysql-5.7.22

./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.22 --datadir=/data/mysql/mysql_data

#安装完会显示临时密码:2018-05-28T09:17:14.020796Z 1 [Note] A temporary password is generated for root@localhost: djyN+y,so2Ka

# 启动数据库

/etc/init.d/mysqld start

./bin/mysql -u root -p -h localhost -S /data/mysql/mysql_data/mysql.sock

(3)修改密码

ALTER USER 'root'@'localhost' identified by '需要设置安全等级很高的密码,否则报错'

alter user 'root'@'localhost' identified by '123456';

(4)授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值