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

- **ID:** `database/mysql-data-directory-permission`
- **Domain:** database
- **Category:** system_error
- **Error Code:** `1017`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MySQL 8.0.x | active | — | — |
| MySQL 5.7.x | active | — | — |
| MariaDB 10.x | active | — | — |

## Workarounds

1. **Fix ownership: chown mysql:mysql /var/lib/mysql/mydb/tables.ibd; then ensure parent directories have correct permissions: chmod 750 /var/lib/mysql/mydb** (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
   ```
2. **If using AppArmor or SELinux, check and update policies: ausearch -m avc -ts recent; then restorecon -R /var/lib/mysql** (80% success)
   ```
   If using AppArmor or SELinux, check and update policies: ausearch -m avc -ts recent; then restorecon -R /var/lib/mysql
   ```

## Dead Ends

- **Running chmod 777 on the .ibd file** — Excessive permissions can cause security issues and MySQL may still fail if the parent directory permissions are wrong; also not a sustainable fix. (70% fail)
- **Restarting MySQL without fixing permissions** — Restarting does not change file permissions; the error will reappear on the next access. (95% fail)
