
[root@docker vagrant]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7 latest 7d0b68af5a06 days ago 694MB
[root@docker vagrant]# docker run -d -v /vagrant/mysql_soft:/opt/mysql -v /vagrant/data1:/data -v /etc/hosts:/etc/hosts -p2222: --cap-add=NET_ADMIN --name c1 -h docker centos7
fbf17e3f6aa8324b8d494aa0211122f5d735bf6f648a99b6632ae2be5be996da
[root@docker vagrant]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fbf17e3f6aa8 centos7 "/usr/bin/supervisor…" seconds ago Up seconds (healthy) 0.0.0.0:->/tcp c1
103f318448c9 centos7 "/usr/bin/supervisor…" minutes ago Exited () minutes ago node1
[root@docker vagrant]# docker rm container 103f318448c9
103f318448c9
Error: No such container: container
[root@docker vagrant]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fbf17e3f6aa8 centos7 "/usr/bin/supervisor…" seconds ago Up seconds (healthy) 0.0.0.0:->/tcp c1
[root@docker vagrant]# ssh root@172.17.0.2
root@172.17.0.2's password:
Last login: Wed Jun :: from 172.17.0.1
[root@docker ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/docker-:--60de86a769f75e2e96c849e76f1b3de10ac8c8d9985597ff3f758070edada54d 10G 682M .4G % /
tmpfs 64M 64M % /dev
tmpfs 497M 497M % /sys/fs/cgroup
none 612G 242G 370G % /data
/dev/mapper/centos-root .4G .1G .3G % /etc/hosts
shm 64M 64M % /dev/shm
tmpfs 497M 497M % /proc/scsi
tmpfs 497M 497M % /sys/firmware
Download and extract MySQL software.
[root@docker ~]# cd /vagrant/mysql_soft
[root@docker mysql_soft]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
[root@docker mysql_soft]# cd /opt/mysql
[root@docker mysql]# ls -l
total
-rwxrwxrwx Mar : mysql-5.7.-linux-glibc2.-x86_64.tar.gz
-rwxrwxrwx Jun : mysql-8.0.-linux-glibc2.-x86_64.tar.gz
[root@docker mysql]# tar -zxf mysql-8.0.-linux-glibc2.-x86_64.tar.gz
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/libcrypto.so: Cannot create symlink to `libcrypto.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/libmysqlclient.so: Cannot create symlink to `libmysqlclient.so.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/libmysqlclient.so.: Cannot create symlink to `libmysqlclient.so.21.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/libssl.so: Cannot create symlink to `libssl.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/plugin/libssl.so.1.0.: Cannot create symlink to `../../lib/libssl.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/plugin/libcrypto.so.1.0.: Cannot create symlink to `../../lib/libcrypto.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/plugin/debug/libssl.so.1.0.: Cannot create symlink to `../../../lib/libssl.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/lib/plugin/debug/libcrypto.so.1.0.: Cannot create symlink to `../../../lib/libcrypto.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/bin/libssl.so.1.0.: Cannot create symlink to `../lib/libssl.so.1.0.': Protocol error
tar: mysql-8.0.-linux-glibc2.-x86_64/bin/libcrypto.so.1.0.: Cannot create symlink to `../lib/libcrypto.so.1.0.': Protocol error
tar: Exiting with failure status due to previous errors
Check absent "libxxx.so" then install them untill there're no "not found" results.
[root@docker mysql]# ldd /usr/local/mysql/bin/mysqld.sh
ldd: /usr/local/mysql/bin/mysqld.sh: No such file or directory
[root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
linux-vdso.so. => (0x00007fff57cca000)
libpthread.so. => /lib64/libpthread.so. (0x00007f57bc85d000)
libaio.so. => not found
libnuma.so. => not found
libcrypt.so. => /lib64/libcrypt.so. (0x00007f57bc625000)
libssl.so.1.0. => not found
libcrypto.so.1.0. => not found
libdl.so. => /lib64/libdl.so. (0x00007f57bc420000)
librt.so. => /lib64/librt.so. (0x00007f57bc217000)
libstdc++.so. => /lib64/libstdc++.so. (0x00007f57bbf10000)
libm.so. => /lib64/libm.so. (0x00007f57bbc0e000)
libgcc_s.so. => /lib64/libgcc_s.so. (0x00007f57bb9f7000)
libc.so. => /lib64/libc.so. (0x00007f57bb62a000)
/lib64/ld-linux-x86-.so. (0x00007f57bca7f000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f57bb427000)
[root@docker mysql]# yum install -y libaio numactl libssl libcrypto
-- Omitted
[root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
linux-vdso.so. => (0x00007fff05f82000)
libpthread.so. => /lib64/libpthread.so. (0x00007fc18aca3000)
libaio.so. => /lib64/libaio.so. (0x00007fc18aaa0000)
libnuma.so. => /lib64/libnuma.so. (0x00007fc18a894000)
libcrypt.so. => /lib64/libcrypt.so. (0x00007fc18a65d000)
libssl.so.1.0. => not found
libcrypto.so.1.0. => not found
libdl.so. => /lib64/libdl.so. (0x00007fc18a458000)
librt.so. => /lib64/librt.so. (0x00007fc18a24f000)
libstdc++.so. => /lib64/libstdc++.so. (0x00007fc189f48000)
libm.so. => /lib64/libm.so. (0x00007fc189c46000)
libgcc_s.so. => /lib64/libgcc_s.so. (0x00007fc189a2f000)
libc.so. => /lib64/libc.so. (0x00007fc189662000)
/lib64/ld-linux-x86-.so. (0x00007fc18aec5000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fc18945f000)
[root@docker mysql]# find / -name libssl.so.1.0.
/opt/mysql/mysql-8.0.-linux-glibc2.-x86_64/lib/libssl.so.1.0.
[root@docker mysql]# cp /opt/mysql/mysql-8.0.-linux-glibc2.-x86_64/lib/libssl.so.1.0. /usr/lib64
[root@docker mysql]# find / -name libcrypto.so.1.0.
/opt/mysql/mysql-8.0.-linux-glibc2.-x86_64/lib/libcrypto.so.1.0.
[root@docker mysql]# cp /opt/mysql/mysql-8.0.-linux-glibc2.-x86_64/lib/libcrypto.so.1.0. /usr/lib64
[root@docker mysql]# ldd /usr/local/mysql/bin/mysqld
linux-vdso.so. => (0x00007fff13ffe000)
libpthread.so. => /lib64/libpthread.so. (0x00007f156dbc3000)
libaio.so. => /lib64/libaio.so. (0x00007f156d9c0000)
libnuma.so. => /lib64/libnuma.so. (0x00007f156d7b4000)
libcrypt.so. => /lib64/libcrypt.so. (0x00007f156d57d000)
libssl.so.1.0. => /lib64/libssl.so.1.0. (0x00007f156d30d000)
libcrypto.so.1.0. => /lib64/libcrypto.so.1.0. (0x00007f156cf25000)
libdl.so. => /lib64/libdl.so. (0x00007f156cd21000)
librt.so. => /lib64/librt.so. (0x00007f156cb18000)
libstdc++.so. => /lib64/libstdc++.so. (0x00007f156c811000)
libm.so. => /lib64/libm.so. (0x00007f156c50f000)
libgcc_s.so. => /lib64/libgcc_s.so. (0x00007f156c2f8000)
libc.so. => /lib64/libc.so. (0x00007f156bf2b000)
/lib64/ld-linux-x86-.so. (0x00007f156dde5000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f156bd28000)
Make required directory and create soft link.
[root@docker mysql]# mkdir -p /data/mysql/mysql3306/{data,logs,tmp}
[root@docker mysql]# ln -sv /opt/mysql/mysql-8.0.-linux-glibc2.-x86_64 /usr/local/mysql
‘/usr/local/mysql’ -> ‘/opt/mysql/mysql-8.0.-linux-glibc2.-x86_64’
Create mysql group & user.
[root@docker mysql]# userdel mysql
[root@docker mysql]# groupadd mysql
[root@docker mysql]# useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql
Modify directory privilege.
[root@docker mysql]# cd /usr/local
[root@docker local]# chown -R mysql.mysql mysql
Modify environment variable.
[root@docker local]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> ~/.bash_profile
[root@docker local]# source ~/.bash_profile
[root@docker local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
Prepare a suitable my.cnf in docker and then copy it to specific path.
[root@docker local]# cp /opt/mysql/my.cnf /data/mysql/mysql3306/my3306.cnf
Initialize MySQL db.
[root@docker local]# mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
mysqld: [Warning] World-writable config file '/data/mysql/mysql3306/my3306.cnf' is ignored.
--23T16::.446641Z [System] [MY-] [Server] mysqld (mysqld 8.0.) initializing of server in progress as process
--23T16::.528638Z [ERROR] [MY-] [Server] Can't find error-message file '/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
--23T16::.804315Z [ERROR] [MY-] [Server] --initialize specified but the data directory has files in it. Aborting.
--23T16::.804363Z [ERROR] [MY-] [Server] Aborting
--23T16::.010408Z [System] [MY-] [Server] mysqld: Shutdown complete (mysqld 8.0.) MySQL Community Server - GPL.
[root@docker ~]# cd /data/mysql/mysql3306/data -- There're no files in the directory,why does it show the existent error?Let's see below.
[root@docker data]# ls -la
total
drwxrwxrwx mysql mysql Jun : .
drwxrwxrwx mysql mysql Jun : ..
I change the way of initialization.
[root@docker data]# mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --user=mysql --initialize
--23T17::.792594Z [System] [MY-] [Server] mysqld (mysqld 8.0.) initializing of server in progress as process
--23T17::.887954Z [Warning] [MY-] [Server] Setting lower_case_table_names= because file system for /data/mysql/mysql3306/data/ is case insensitive
mbind: Operation not permitted
--23T17::.669761Z [Note] [MY-] [Server] A temporary password is generated for root@localhost: o/>k*hqxn1T=
--23T17::.807974Z [System] [MY-] [Server] mysqld (mysqld 8.0.) initializing of server has completed
[root@docker etc]# ps aux | grep mysqld
root 0.0 0.0 pts/ SN+ : : grep --color=auto mysqld
Start mysqld but failed.
[root@docker etc]# mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
[]
[root@docker etc]# mysqld: [Warning] World-writable config file '/data/mysql/mysql3306/my3306.cnf' is ignored.
--23T17::.345108Z [System] [MY-] [Server] mysqld (mysqld 8.0.) starting as process
--23T17::.346090Z [ERROR] [MY-] [Server] Can't find error-message file '/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
--23T17::.357718Z [Warning] [MY-] [Server] Setting lower_case_table_names= because file system for /data/ is case insensitive
--23T17::.358228Z [ERROR] [MY-] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
--23T17::.358263Z [ERROR] [MY-] [Server] Aborting
--23T17::.362713Z [System] [MY-] [Server] mysqld: Shutdown complete (mysqld 8.0.) MySQL Community Server - GPL.
^C
[]+ Exit mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf
The my3306.cnf cannot be world-writable,so I copy it to "/tmp" and start mysqld again.
[root@docker etc]# cp /data/mysql/mysql3306/my3306.cnf /tmp
[root@docker etc]# cd /tmp
[root@docker tmp]# ls -l | grep my3306.cnf
-rwxr-xr-x root root Jun : my3306.cnf
[root@docker tmp]# mysqld --defaults-file=/tmp/my3306.cnf &
[]
[root@docker tmp]# ps aux | grep mysqld
root 0.0 0.0 pts/ SN+ : : grep --color=auto mysqld
[]+ Exit mysqld --defaults-file=/tmp/my3306.cnf
[root@docker etc]# tail /data/mysql/mysql3306/data/error.log
--24T01::03.732865+: [Warning] [MY-] [Server] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
--24T01::03.735145+: [Warning] [MY-] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
--24T01::03.736465+: [System] [MY-] [Server] mysqld (mysqld 8.0.) starting as process
mbind: Operation not permitted
--24T01::04.184074+: [ERROR] [MY-] [InnoDB] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size pages (rounded down to MB) than specified in the .cnf file: initial pages, max (relevant if non-zero) pages!
--24T01::04.184868+: [ERROR] [MY-] [InnoDB] InnoDB: Plugin initialization aborted with error Generic error.
--24T01::04.810086+: [ERROR] [MY-] [Server] Failed to initialize DD Storage Engine
--24T01::04.810840+: [ERROR] [MY-] [Server] Data Dictionary initialization failed.
--24T01::04.810961+: [ERROR] [MY-] [Server] Aborting
--24T01::04.828841+: [System] [MY-] [Server] mysqld: Shutdown complete (mysqld 8.0.) MySQL Community Server - GPL.
It still has problem 'cause size of "./ibdata1" is incompatible with the parameter in "my3306.cnf".
[root@docker data]# ls -l ibdata1
-rwxrwxrwx mysql mysql Jun : ibdata1
[root@docker data]# cat /tmp/my3306.cnf | grep innodb_data_file_path
innodb_data_file_path =ibdata1:100M:autoextend # ibdata1:12M:autoextend
[root@docker data]# vim /tmp/my3306.cnf | grep innodb_data_file_path
[root@docker data]# cat /tmp/my3306.cnf | grep innodb_data_file_path
innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend
After I started mysqld several seconds later,the process down again at once.
[root@docker etc]# mysqld --defaults-file=/tmp/my3306.cnf &
[]
[root@docker etc]# ps aux|grep mysqld
mysql 38.0 3.1 pts/ SNl : : mysqld --defaults-file=/tmp/my3306.cnf
root 0.0 0.0 pts/ SN+ : : grep --color=auto mysqld
[root@docker etc]# ps aux|grep mysqld
root 0.0 0.0 pts/ SN+ : : grep --color=auto mysqld
[root@docker etc]#
[root@docker data]# tail - error.log
--24T01::30.177384+: [Warning] [MY-] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
--24T01::30.179005+: [System] [MY-] [Server] mysqld (mysqld 8.0.) starting as process
mbind: Operation not permitted --24T01::33.215591+: [ERROR] [MY-] [Server] Different lower_case_table_names settings for server ('') and data dictionary ('').
--24T01::33.216211+: [ERROR] [MY-] [Server] Data Dictionary initialization failed.
--24T01::33.216289+: [ERROR] [MY-] [Server] Aborting
--24T01::34.839683+: [System] [MY-] [Server] mysqld: Shutdown complete (mysqld 8.0.) MySQL Community Server - GPL.
The error shows that the value is not equal between "lower_case_table_names" and dictionary.
[root@docker data]# cat /opt/mysql/my.cnf|grep lower_case_table_names
lower_case_table_names = #
[root@docker data]# cat /tmp/my3306.cnf | grep lower_case_table_names
lower_case_table_names = #
[root@docker data]# vim /tmp/my3306.cnf
[root@docker data]# cat /tmp/my3306.cnf | grep lower_case_table_names
lower_case_table_names = #
After I've modified my3306.cnf,it seems no error occurs now.
[root@docker data]# tail - error.log
--24T01::20.035831+: [Warning] [MY-] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode.
--24T01::20.035971+: [Warning] [MY-] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
--24T01::20.036064+: [Warning] [MY-] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
--24T01::20.036160+: [Warning] [MY-] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
--24T01::20.036898+: [Warning] [MY-] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
--24T01::20.037083+: [Warning] [MY-] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
--24T01::20.037268+: [Warning] [MY-] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
--24T01::20.042517+: [Warning] [MY-] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
--24T01::20.042646+: [Warning] [MY-] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
--24T01::20.099046+: [System] [MY-] [Server] mysqld: ready for connections. Version: '8.0.11' socket: '/tmp/mysql.sock' port: MySQL Community Server - GPL.
[root@docker etc]# ps aux|grep mysqld
mysql 2.0 9.3 pts/ SNl : : mysqld --defaults-file=/tmp/my3306.cnf
root 0.0 0.0 pts/ SN+ : : grep --color=auto mysqld
Start mysql client and modify the password generated by initialization.
[root@docker etc]# mysql
ERROR (): Access denied for user 'root'@'localhost' (using password: NO)
[root@docker etc]# mysql -p
Enter password: -- Use the password which generated by initialization(here is "o/>k*hqxn1T=")
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 8.0. Copyright (c) , , Oracle and/or its affiliates. All rights reserved. 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> show databases;
ERROR (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user root@localhost identified by 'Passw0rd';
Query OK, rows affected (0.11 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.20 sec) mysql>
- ldd can be used to check if mysqld is missing "libxxx.so" file.Then you can install or copy directly into "/usr/lib64" directory.
- There're many errors in my installation procedure due to inappropriate parameters.
- Because of the vagrant,all the shared directories in docker contains also has the 777 privilege what cause the world-writable issue.
- Since MySQL 5.7,password of root@localhost must be changed while first login.Otherwise,you can do nothing at all.