mysql 启动报错 Can‘t change dir to ‘xxx‘, No such file or directory 配置错误或挂载导致

省流:

挂载的话,使用 /etc/fstab

正文:

在企业中,服务器重启,有时候会遇到mysql 启动报错 Can`t change dir to 'xxx', No such file or directory。大致意思是无法将目录换成xxx,因为没有这个目录。

原因通常是配置文件配置的目录有问题,或者挂载盘加载慢于mysql启动(mysql的data数据放在挂载盘里)

linux中配置文件是my.cnf,通常路径是 /etc/my.cnf

windows中配置文件是my.ini,

mysql配置文件大致内容如下:

bash 复制代码
# mysql路径
basedir=/sata09/data/mysql
# mysql存数据的路径
datadir=/sata09/data/mysql/data

这篇文章以挂载问题导致为例。

挂载有两种:

rc.local,fstab。最好使用fstab,原因如下:

开机挂载mount,/etc/fstab与/etc/rc.d/rc.local区别差不多,差别就是如果你又程序依赖于NFS的话还是的放到fstab比较好。程序启动先加载/etc/fastab文件。

放fstab里面会在程序启动前加载上NFS文件系统,放到rc.local里往往造成程序启动加载时找不到路径

我之前的挂载命令是放在/etc/rc.local,现在需要放在/etc/fstab

bash 复制代码
mount /prd/ssd/ssd01   /ssd01   
mount /prd/sata/sata01   /sata01

详细日志如下:

cs 复制代码
Oct 17 02:50:32 ali5messrv1 mysqld: mysqld: Can`t change dir to '/sata09/data/mysql/' (Errcode: 2 - No such file or directory)
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060197Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060311Z 0 [Warning] Can`t create test file /sata09/data/mysql/ali5messrv1.lower-test
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060344Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.32-log) starting as process 3280 ...
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060369Z 0 [ERROR] Can`t find error-message file '/sata09/data/mysql/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060943Z 0 [Warning] Can`t create test file /sata09/data/mysql/ali5messrv1.lower-test
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060950Z 0 [Warning] Can`t create test file /sata09/data/mysql/ali5messrv1.lower-test
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060990Z 0 [ERROR] failed to set datadir to /sata09/data/mysql/
Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060998Z 0 [ERROR] Aborting

Oct 17 02:50:32 ali5messrv1 systemd[1]: Starting MySQL Server...
Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: mysqld: Can't create directory '/sata09/data/mysql/' (Errcode: 2 - No s...tory)
Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867006Z 0 [Warning] TIMESTAMP with implicit DEFAULT...ils).
Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867111Z 0 [ERROR] Can't find error-message file '/s...tive.
Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867941Z 0 [ERROR] Aborting
Oct 17 02:52:03 ali5messrv1 systemd[1]: Started MySQL Server.

开机挂载mount etc/fstab与/etc/rc.d/rc.local区别-阿里云开发者社区

Oct 17 02:50:32 ali5messrv1 mysqld: mysqld: Can't change dir to '/sata09/data/mysql/' (Errcode: 2 - No such file or directory)

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060197Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060311Z 0 [Warning] Can't create test file /sata09/data/mysql/ali5messrv1.lower-test

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060344Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.32-log) starting as process 3280 ...

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060369Z 0 [ERROR] Can't find error-message file '/sata09/data/mysql/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060943Z 0 [Warning] Can't create test file /sata09/data/mysql/ali5messrv1.lower-test

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060950Z 0 [Warning] Can't create test file /sata09/data/mysql/ali5messrv1.lower-test

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060990Z 0 [ERROR] failed to set datadir to /sata09/data/mysql/

Oct 17 02:50:32 ali5messrv1 mysqld: 2023-10-16T18:50:32.060998Z 0 [ERROR] Aborting

Oct 17 02:50:32 ali5messrv1 systemd[1]: Starting MySQL Server...

Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: mysqld: Can't create directory '/sata09/data/mysql/' (Errcode: 2 - No s...tory)

Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867006Z 0 [Warning] TIMESTAMP with implicit DEFAULT...ils).

Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867111Z 0 [ERROR] Can't find error-message file '/s...tive.

Oct 17 02:50:32 ali5messrv1 mysqld_pre_systemd[2476]: 2023-10-16T18:50:32.867941Z 0 [ERROR] Aborting

Oct 17 02:52:03 ali5messrv1 systemd[1]: Started MySQL Server.

相关推荐
瓜牛_gn5 小时前
mysql特性
数据库·mysql
Yaml410 小时前
Spring Boot 与 Vue 共筑二手书籍交易卓越平台
java·spring boot·后端·mysql·spring·vue·二手书籍
追风林10 小时前
mac 本地docker-mysql主从复制部署
mysql·macos·docker
Hsu_kk12 小时前
MySQL 批量删除海量数据的几种方法
数据库·mysql
编程学无止境12 小时前
第02章 MySQL环境搭建
数据库·mysql
knight-n12 小时前
MYSQL库的操作
数据库·mysql
eternal__day14 小时前
MySQL_聚合函数&分组查询
数据库·mysql
咕哧普拉啦14 小时前
乐尚代驾十订单支付seata、rabbitmq异步消息、redisson延迟队列
java·spring boot·mysql·spring·maven·乐尚代驾·java最新项目
春哥的魔法书15 小时前
数据库基础(5) . DCL
数据库·mysql
鬼才血脉16 小时前
docker+mysql配置
mysql·adb·docker