# 这里是整个项目所需要的文件,包括离线下载mysql 8.0的包
[11:26:19 root@centos7 mysql]#tree
.
├── Dockerfile
├── my.cnf
├── mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz
└── mysql.sh
#开始编辑Dockerfile
[11:26:23 root@centos7 mysql]#cat Dockerfile
FROM centos:7
LABEL <noise@admin.com> noiseLys
RUN yum -y install numactl libaio vim-enhanced tcpdump lrzsz tree telnet bashcompletion net-tools wget bzip2 lsof tmux man-pages zip unzip nfs-utils gcc make gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel
RUN groupadd mysql
RUN useradd -r -g mysql -s /bin/false mysql
ADD mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz /usr/local/
RUN cd /usr/local/ && \
ln -s mysql-8.0.23-linux-glibc2.12-x86_64/ mysql && \
mkdir -pv /data/mysql/logbin/ && \
mkdir -pv /data/mysql/data && \
chown -R root.root /usr/local/mysql/ && \
chown -R mysql.mysql /data/mysql
ADD mysql.sh /etc/profile.d/
RUN source /etc/profile.d/mysql.sh
ADD my.cnf /etc/
RUN /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql/data
RUN cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
CMD ["chkconfig","--add","mysqld"]
EXPOSE 3306
CMD ["/etc/init.d/mysqld","start"]
# mysql配置文件
[11:26:41 root@centos7 mysql]#cat my.cnf
[mysqld]
datadir=/data/mysql/data
skip_name_resolve=1
socket=/data/mysql/mysql.sock
explicit_defaults_for_timestamp=true
log_bin=/data/mysql/logbin/mysql-binlog
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
log_timestamps=SYSTEM
server-id=1
[client]
socket=/data/mysql/mysql.sock
[mysql]
prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"
# mysql的path路径
[11:26:52 root@centos7 mysql]#cat mysql.sh
PATH=/usr/local/mysql/bin:$PATH
# build docker ps
[11:17:02 root@centos7 mysql]#docker build -t mysql:v1.6 .
# 查看是否成功
[11:06:26 root@centos7 mysql]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql v1.6 6316eab45473 15 seconds ago 3.61GB
# 开始运行docker
[11:06:41 root@centos7 mysql]#docker run -it mysql:v1.6 bash
[root@4a830be8da0d /]# msyql
bash: msyql: command not found
[root@4a830be8da0d /]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2)
[root@4a830be8da0d /]# /usr/local/mysql/bin/mysqld_safe #--》 用这个启动
2021-06-27T03:08:23.787636Z mysqld_safe Logging to '/data/mysql/mysql.log'.
2021-06-27T03:08:23.825849Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
#结束容器退出
^Z
[1]+ Stopped /usr/local/mysql/bin/mysqld_safe
[root@4a830be8da0d /]#
[root@4a830be8da0d /]#
[root@4a830be8da0d /]# exit
exit
There are stopped jobs.
[root@4a830be8da0d /]# kill -9 19
[root@4a830be8da0d /]#
[1]+ Killed /usr/local/mysql/bin/mysqld_safe
[root@4a830be8da0d /]# exit
exit
# 开多一个窗口访问mysql
[11:11:25 root@centos7 ~]#docker exec -it 4a830be8da0d bash
[root@4a830be8da0d /]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
03:11:39(root@localhost) [(none)]> exit
Bye
[root@4a830be8da0d /]#
[root@4a830be8da0d /]# exit
exit