Error
Error Code: 13

MySQL Error 13: Cannot Access File Metadata

📦 MySQL
📋

Description

This error indicates that the MySQL server process was unable to retrieve file system information (like permissions, size, or existence) for a specified file or directory. It typically occurs when MySQL attempts to read or write data files, log files, or configuration files but lacks the necessary operating system permissions or the file path is incorrect.
💬

Error Message

Can't get stat of '%s' (OS errno %d - %s)
🔍

Known Causes

3 known causes
⚠️
Insufficient File Permissions
The operating system user running MySQL lacks the necessary read or execute permissions for the specified file or directory, preventing access to its metadata.
⚠️
Non-existent File or Path
MySQL attempted to access a file or directory at a path that does not exist, or has been moved or deleted from the system.
⚠️
Incorrect File Ownership
The file or directory is owned by a different user or group, and the MySQL process does not have access rights.
🛠️

Solutions

3 solutions available

1. Verify File and Directory Permissions easy

Ensure the MySQL user has read and execute permissions on the target file and its parent directories.

1
Identify the file path mentioned in the error message. This is typically a data file, log file, or configuration file.
2
Check the permissions of the identified file and its parent directories. The MySQL server process (often running as the 'mysql' user) needs read and execute permissions.
ls -ld /path/to/directory
ls -l /path/to/file
3
If permissions are insufficient, grant the necessary permissions. Replace `/path/to/directory` and `/path/to/file` with the actual paths.
sudo chown -R mysql:mysql /path/to/directory
sudo chmod -R u+rwX,g+rX,o-rwx /path/to/directory
sudo chmod u+rw,g+r,o-rwx /path/to/file
4
Restart the MySQL service to apply the permission changes.
sudo systemctl restart mysql

2. Check for SELinux or AppArmor Restrictions medium

Disable or reconfigure SELinux or AppArmor if they are preventing MySQL from accessing files.

1
Check the status of SELinux. If enabled, it might be blocking access. Look for 'SELinux status: enabled'.
sestatus
2
If SELinux is the issue, you can temporarily disable it for testing (not recommended for production). Replace `enforcing` with `permissive` for less restrictive mode.
sudo setenforce 0
3
If SELinux is confirmed as the cause, you'll need to create or adjust SELinux policies to allow MySQL access to the specific file or directory. This is an advanced topic and requires careful consideration of security implications.
4
Alternatively, check AppArmor status. Look for 'AppArmor status: enabled'.
sudo apparmor_status
5
If AppArmor is blocking access, you may need to adjust its profiles. For example, to put a profile in complain mode (which logs but doesn't block):
sudo aa-complain /path/to/mysql/binary
6
Restart MySQL after making SELinux or AppArmor changes.
sudo systemctl restart mysql

3. Verify File System Integrity and Disk Space medium

Ensure the underlying file system is healthy and has sufficient free space.

1
Check the disk space on the partition where the MySQL data directory resides.
df -h
2
If disk space is low, free up space by removing unnecessary files or expanding the storage. This is critical, as full disks can cause various I/O errors.
3
Check the file system for errors. This might involve unmounting the partition and running `fsck` (be cautious with this on live systems).
sudo fsck /dev/sdXn
4
Monitor system logs (e.g., `/var/log/syslog`, `/var/log/messages`) for any file system-related errors that might indicate underlying corruption.
🔗

Related Errors

5 related errors