[root@localhost ~]# ll /var/lib/mysql/
total 110604
-rw-rw---- 1 polkitd ssh_keys 56 Sep 14 15:46 auto.cnf
drwx------ 2 polkitd ssh_keys 131 Sep 14 16:03 db1
drwx------ 2 polkitd ssh_keys 131 Sep 14 16:03 db2
drwx------ 2 polkitd ssh_keys 55 Sep 14 16:02 db3
-rw-rw---- 1 polkitd ssh_keys 12582912 Sep 24 10:08 ibdata1
-rw-rw---- 1 polkitd ssh_keys 50331648 Sep 24 10:08 ib_logfile0
-rw-rw---- 1 polkitd ssh_keys 50331648 Sep 14 15:45 ib_logfile1
drwx------ 2 polkitd ssh_keys 4096 Sep 23 14:18 mysql
drwx------ 2 polkitd ssh_keys 4096 Sep 22 13:47 performance_schema
属主为polkitd,属组为ssh_keys。
再来启动宿主机的mysql服务试试,竟然失败了。
[root@localhost ~]# systemctl start mysql
Failed to issue method call: Unit mysql.service failed to load: No such file or directory.
[root@localhost ~]# systemctl start mysqld
Job for mysqld.service failed. See 'systemctl status mysqld.service' and 'journalctl -xn' for details.
[root@localhost ~]# systemctl status mysqld.service
mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld)
Active: failed (Result: exit-code) since Thu 2015-09-24 10:23:25 CST; 13s ago
Process: 3501 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Sep 24 10:23:13 localhost.localdomain systemd[1]: Starting SYSV: MySQL database server....
Sep 24 10:23:25 localhost.localdomain mysqld[3501]: MySQL Daemon failed to start.
Sep 24 10:23:25 localhost.localdomain mysqld[3501]: Starting mysqld: [FAILED]
Sep 24 10:23:25 localhost.localdomain systemd[1]: mysqld.service: control process exited, code=exited status=1
Sep 24 10:23:25 localhost.localdomain systemd[1]: Failed to start SYSV: MySQL database server..
Sep 24 10:23:25 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
即便删除了容器也不行,关于Docker挂载目录的问题,可参考另外一篇博客,关于Docker目录挂载的总结。
关于这个问题的解决,目前还没找到方法,即便重新对/var/lib/mysql设置属主和属组也不行,我最后用的是一个粗暴的方法,直接rm -rf /var/lib/mysql/,然后重启服务。
6>
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set'
echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?'
exit 1
fi
设置mysql的root账户的密码,其中-z判断是否为空字符串,-a 两个条件同时满足,才为true。从这里也可以看出来,随意给MYSQL_ALLOW_EMPTY_PASSWORD赋一个值,都可以实现无密码登录。
7>
mkdir -p "$DATADIR"
chown -R mysql:mysql "$DATADIR"
echo 'Running mysql_install_db'
mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --keep-my-cnf
echo 'Finished mysql_install_db'
mysqld --user=mysql --datadir="$DATADIR" --skip-networking &
pid="$!"
创建/var/lib/mysql,同时将其属主和属组设置为mysql,然后初始化数据库,最后用mysqld命令启动数据库。$!指的是Shell最后运行的后台Process的PID。
8>
mysql=( mysql --protocol=socket -uroot )