1017 database system_error ai_generated true

ERROR 1017 (HY000): Can't find file: './mydb/tables.ibd' (errno: 13 - Permission denied)

ID: database/mysql-data-directory-permission

Also available as: JSON · Markdown · 中文
88%Fix Rate
88%Confidence
1Evidence
2023-07-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
MySQL 8.0.x active
MySQL 5.7.x active
MariaDB 10.x active

Root Cause

The MySQL server process cannot read or write the .ibd file due to incorrect file permissions or ownership on the data directory.

generic

中文

MySQL 服务器进程由于数据目录上的文件权限或所有权不正确,无法读取或写入 .ibd 文件。

Official Documentation

https://dev.mysql.com/doc/refman/8.0/en/data-directory.html

Workarounds

  1. 90% success Fix ownership: chown mysql:mysql /var/lib/mysql/mydb/tables.ibd; then ensure parent directories have correct permissions: chmod 750 /var/lib/mysql/mydb
    Fix ownership: chown mysql:mysql /var/lib/mysql/mydb/tables.ibd; then ensure parent directories have correct permissions: chmod 750 /var/lib/mysql/mydb
  2. 80% success If using AppArmor or SELinux, check and update policies: ausearch -m avc -ts recent; then restorecon -R /var/lib/mysql
    If using AppArmor or SELinux, check and update policies: ausearch -m avc -ts recent; then restorecon -R /var/lib/mysql

中文步骤

  1. 修复所有权:chown mysql:mysql /var/lib/mysql/mydb/tables.ibd;然后确保父目录权限正确:chmod 750 /var/lib/mysql/mydb
  2. 如果使用 AppArmor 或 SELinux,检查和更新策略:ausearch -m avc -ts recent;然后 restorecon -R /var/lib/mysql

Dead Ends

Common approaches that don't work:

  1. Running chmod 777 on the .ibd file 70% fail

    Excessive permissions can cause security issues and MySQL may still fail if the parent directory permissions are wrong; also not a sustainable fix.

  2. Restarting MySQL without fixing permissions 95% fail

    Restarting does not change file permissions; the error will reappear on the next access.