docker 启动 mysql 8.0.1 出现异常

mysql

该问题是采用了 mysql 8.1.x 的 docker镜像版本,运行一段时间后产生的 异常,每次重新启动后没过几分钟容器就又挂掉,并且还会导致服务器很卡,通过 docker logs [容器id], 可看到如下错误信息:

mbind: Operation not permitted mbind: Operation not permitted mbind: Operation not permitted mbind: Operation not permitted 2019-05-04T16:29:35.596353Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2019-05-04T16:29:35.596545Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 1 2019-05-04T16:29:41.770754Z 0 [System] [MY-010229] [Server] Starting crash recovery... 2019-05-04T16:29:42.036965Z 0 [System] [MY-010232] [Server] Crash recovery finished. 2019-05-04T16:29:42.437394Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2019-05-04T16:29:42.504001Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 2019-05-04T16:29:42.612079Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.infoschema@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612129Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612142Z 0 [Warning] [MY-010315] [Server] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612153Z 0 [Warning] [MY-010315] [Server] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612210Z 0 [Warning] [MY-010323] [Server] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612222Z 0 [Warning] [MY-010323] [Server] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.612239Z 0 [Warning] [MY-010311] [Server] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.775854Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.775903Z 0 [Warning] [MY-010330] [Server] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode. 2019-05-04T16:29:42.846711Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL. 2019-05-04T16:29:44.182618Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
解决思路
# 重新启动容器
docker start [容器ID]

# 进入mysql容器
docker exec -it [容器ID] /bin/bash

# 登录mysql,执行以下会出现输入密码
mysql -u root -p

# 查看用户信息(host为 % 表示不限制ip,localhost表示本机使用,plugin非mysql_native_password 则需要修改密码)
select host,user,plugin,authentication_string from mysql.user;

# 更新密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';

最后使用新的账号密码连接数据库即可。