[root@16256ee64b9e src]# ls
debug kernels mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@16256ee64b9e src]#
[root@16256ee64b9e src]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs libaio numactl
[root@16256ee64b9e src]# useradd -r -M -s /sbin/nologin mysql
[root@16256ee64b9e src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@16256ee64b9e src]# mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
[root@16256ee64b9e src]# cd /usr/local/
[root@16256ee64b9e local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
[root@16256ee64b9e local]# chown -R mysql.mysql /usr/local/mysql
[root@16256ee64b9e local]# mkdir /opt/data
[root@16256ee64b9e local]# chown -R mysql.mysql /opt/data
[root@16256ee64b9e local]# /usr/local/mysql/bin/mysqld –initialize-insecure –user=mysql –datadir=/opt/data
2021-12-06T02:53:34.095554Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-06T02:53:35.482793Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-12-06T02:53:35.506011Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-12-06T02:53:35.562063Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b4aa24d8-563f-11ec-80a8-0242ac110003.
2021-12-06T02:53:35.562798Z 0 [Warning] Gtid table is not ready to be used. Table mysql.gtid_executed cannot be opened.
2021-12-06T02:53:35.979249Z 0 [Warning] CA certificate ca.pem is self signed.
2021-12-06T02:53:36.217615Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the –initialize-insecure option.
[root@16256ee64b9e local]#
[root@16256ee64b9e local]# echo export PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh
[root@16256ee64b9e local]# . /etc/profile.d/mysql.sh
[root@16256ee64b9e local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@16256ee64b9e local]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@16256ee64b9e local]# cat /etc/m
machine-id modprobe.d/ motd my.cnf
makedumpfile.conf.sample modules-load.d/ mtab my.cnf.d/
[root@16256ee64b9e local]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
[root@16256ee64b9e local]#
[root@16256ee64b9e local]# sed -ri s#^(basedir=).*#\1/usr/local/mysql#g /usr/local/mysql/support-files/mysql.server
[root@16256ee64b9e local]# sed -ri s#^(datadir=).*#\1/opt/data#g /usr/local/mysql/support-files/mysql.server
[root@16256ee64b9e local]# sed -n 46,1p /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
[root@16256ee64b9e local]# sed -n 47,1p /usr/local/mysql/support-files/mysql.server
datadir=/opt/data
[root@16256ee64b9e local]# sed -n 46,47p /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/opt/data
[root@16256ee64b9e local]#
[root@16256ee64b9e ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to /opt/data/16256ee64b9e.err.
SUCCESS!
[root@16256ee64b9e ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 *:3306 *:*
[root@16256ee64b9e ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 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.
mysql> set password = password(123);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[root@16256ee64b9e ~]#
[root@16256ee64b9e ~]# mkdir /scripts
[root@16256ee64b9e ~]# vi /scripts/start.sh
[root@16256ee64b9e ~]# sed -n 1,3p /scripts/start.sh
#!/bin/bash
/usr/local/mysql/support-files/mysql.server start
/bin/bash
[root@16256ee64b9e ~]# chmod +x /scripts/start.sh
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
pengyudong/nginx v1 2153a12060f6 28 minutes ago 576MB
centos latest 5d0da3dc9764 2 months ago 231MB
[root@localhost ~]# docker commit -c CMD [“/scripts/start.sh”] -p mysql pengyudong/mysql:v1
sha256:9c8b9aa2d9177e737138f7a42976210fd6e7b039cb543c306281be72c351806e
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
pengyudong/mysql v1 9c8b9aa2d917 4 seconds ago 3.81GB
pengyudong/nginx v1 2153a12060f6 30 minutes ago 576MB
centos latest 5d0da3dc9764 2 months ago 231MB