项目场景:
由于通知服务器所在区域停电检修,服务器需关机,同时此服务器有mysql8 docker容器也需要停止。
问题描述
mysql8 docker容器停止后,重新启动,报异常mysqld: Error on realpath() on ‘/var/lib/mysql-files’ (Error 2 - No such file or directory)
日志如下:
mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2023-11-24T12:58:51.832273Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2023-11-24T12:58:51.832342Z 0 [ERROR] [MY-010119] [Server] Aborting
原因分析:
1、以为是mysqld: Error on realpath() on ‘/var/lib/mysql-files’ (Error 2 - No such file or directory) 查找资料,因为my.cnf中secure-file-priv=null ,想着重新创建容器配置该参数来尝试。后来查找资料了解到secure-file-priv只是不允许数据导入导出,应该跟该配置没有关系,从而没有重新创建容器。
2、mysqld: [Warning] World-writable config file ‘/etc/mysql/my.cnf’ is ignored. 留意到该语句,猜测是由于my.cnf被忽略才出现的mysqld: Error on realpath() on ‘/var/lib/mysql-files’ 。查找资料了解到是文件权限问题。
你在使用Docker运行MySQL时遇到了一个警告,内容是“World-writable config file ‘/etc/my.cnf’ is ignored”。这个警告的意思是,MySQL配置文件’/etc/my.cnf’的权限设置过于开放(world-writable),因此被MySQL忽略了。
对于数据库配置文件来说,在大多数情况下只需要数据库管理员或者root用户有读写权即可。如果所有人都可以修改这些配置信息,则可能会导致数据泄露或者其他安全问题。
所以:使其只有root/当前用户有读写权,其他用户只有读的权限 chmod 644 my.cnf 就可以了
解决方案:
修改my.cnf权限:使其只有root/当前用户有读写权,其他用户只有读的权限
chmod 644 my.cnf
其他:
解决完启动问题后,无法通过工具连接mysql数据库:DBeaver7.0.4 连接工具出现[mysql] Public Key Retrieval is not allowed
可能是连接工具本身问题。
解决方案:
mysql docker重启后,DBeaver7.0.4需关闭重新打开,就能正常连接了。
参考文献:
分析关于Mysql容器启动失败恢复的问题
[mysql] Public Key Retrieval is not allowed