Error 2 (EE_READ) occurs when MySQL cannot read a file it needs to access, typically due to file permissions, missing files, or filesystem issues. This error prevents database operations and requires checking file access rights and data integrity.
Fixes EE_READ (2): Error reading file
# View recent error log entries
sudo tail -100 /var/log/mysql/error.log
# or
sudo tail -100 /var/log/mysqld.log
# Search for EE_READ errors specifically
sudo grep "EE_READ|Error reading" /var/log/mysql/error.log | tail -20# View recent error log entriessudo tail -100 /var/log/mysql/error.log# orsudo tail -100 /var/log/mysqld.log# Search for EE_READ errors specificallysudo grep "EE_READ|Error reading" /var/log/mysql/error.log | tail -20EE_READ (2): Error reading file
Error 2 (EE_READ) indicates that the MySQL server encountered a problem reading a file it requires. This can occur when MySQL tries to read data files, log files, configuration files, or files referenced by LOAD DATA INFILE statements. The error typically arises when: - The MySQL process lacks read permissions on the file - The file has been moved, deleted, or is inaccessible - The filesystem is experiencing I/O errors - SELinux or AppArmor security policies block the read operation - The file is locked by another process Unlike some SQL syntax errors, EE_READ indicates a system-level problem preventing access to required data, making it a critical issue that blocks query execution.
The error log contains which file MySQL failed to read. Find and examine it:
On Linux/macOS:
# View recent error log entries
sudo tail -100 /var/log/mysql/error.log
# or
sudo tail -100 /var/log/mysqld.log
# Search for EE_READ errors specifically
sudo grep "EE_READ|Error reading" /var/log/mysql/error.log | tail -20On Windows:
C:\ProgramData\MySQL\MySQL Server 8.0\Data\HOSTNAME.errLook for the file path in the error message. The log will show something like:
2024-01-15 10:23:45 123456 [ERROR] [MY-012345] EE_READ (2): Error reading file './mydb/mytable.ibd'Note the exact path returned in the error.
Check if the file mentioned in the error actually exists and can be read:
For data files in the data directory:
# List MySQL data directory
sudo ls -la /var/lib/mysql/
# or check specific database
sudo ls -la /var/lib/mysql/mydb/
# Check if the problem file exists
sudo ls -l /var/lib/mysql/mydb/mytable.ibdIf the file doesn't exist:
- The table may have been deleted by accident
- The file path in a LOAD DATA statement is incorrect
- A migration moved files unexpectedly
If the file exists, check if you can read it as a test user:
# Try reading a small amount of the file
sudo head -c 100 /var/lib/mysql/mydb/mytable.ibd > /dev/null && echo "File is readable" || echo "File is not readable"The MySQL server runs as the 'mysql' user. It must have read permissions on all data files:
Check current permissions:
# Check data directory ownership and permissions
sudo ls -la /var/lib/mysql/ | head -5
# Output should show: drwxr-x--- mysql mysql
# Check specific file/directory permissions
sudo ls -l /var/lib/mysql/mydb/Fix permissions if needed:
# Change ownership to mysql user and group
sudo chown -R mysql:mysql /var/lib/mysql/
# or for a specific database
sudo chown -R mysql:mysql /var/lib/mysql/mydb/
# Set correct permissions (750 for directories, 640 for files)
sudo chmod -R 750 /var/lib/mysql/
sudo chmod -R 640 /var/lib/mysql/**/*.{ibd,MYD,MYI}
# For specific table files
sudo chmod 640 /var/lib/mysql/mydb/mytable.ibd
sudo chown mysql:mysql /var/lib/mysql/mydb/mytable.ibdRestart MySQL to verify the fix:
sudo systemctl restart mysql
sudo systemctl status mysqlSecurity modules can block MySQL file access even with correct permissions:
Check if SELinux is active (Linux):
getenforce
# Output: Enforcing, Permissive, or DisabledCheck SELinux context on MySQL files:
# View SELinux context
sudo ls -Z /var/lib/mysql/
# Should show: mysql_db_t for directories and files
# If context is wrong, restore it:
sudo restorecon -Rv /var/lib/mysql/Check AppArmor (Ubuntu/Debian):
sudo aa-status | grep mysql
# If in "enforce" mode and blocking, check the profile
sudo cat /etc/apparmor.d/usr.sbin.mysqld | grep "^/var/lib/mysql"Temporarily allow all file access to test:
# Put AppArmor in complain mode (logs violations without blocking)
sudo aa-complain /usr/sbin/mysqld
# Restart MySQL and test
sudo systemctl restart mysql
# Check if error is gone
# If gone, AppArmor was the issue; create custom profile or use enforce after fixingDisk errors can cause read failures even if the file exists:
Check system logs for I/O errors:
# Linux: check kernel messages for disk errors
dmesg | grep -i "io error|i/o error" | tail -20
# or check syslog
sudo grep -i "i/o error" /var/log/syslog | tail -20Run filesystem check (requires MySQL shutdown):
# First, stop MySQL
sudo systemctl stop mysql
# Check filesystem (use -n flag for read-only first)
sudo fsck -n /dev/sda1
# If errors found, run repair (WARNING: can take time and may modify files)
sudo fsck -y /dev/sda1
# Restart MySQL
sudo systemctl start mysqlMonitor disk health with smartctl:
# Check if SMART is available
sudo smartctl -i /dev/sda
# Run quick SMART self-test
sudo smartctl -t short /dev/sda
sudo smartctl -a /dev/sda | grep "SMART"If the error occurs during LOAD DATA INFILE, the input file path may be incorrect:
Verify the input file exists and is readable:
# Check if file exists
ls -l /path/to/input/file.csv
# Verify permissions for MySQL to read it
sudo cat /path/to/input/file.csv > /dev/nullUse correct absolute paths in LOAD DATA:
-- WRONG: Relative path (MySQL runs from different directory)
LOAD DATA INFILE 'data.csv'
INTO TABLE mytable;
-- CORRECT: Absolute path
LOAD DATA INFILE '/var/lib/mysql-import/data.csv'
INTO TABLE mytable;If file is outside /var/lib/mysql/, ensure permissions:
# Allow MySQL to read from custom directory
sudo chown mysql:mysql /var/lib/mysql-import/
sudo chmod 750 /var/lib/mysql-import/
sudo chmod 640 /var/lib/mysql-import/data.csvOn Docker, mount volumes correctly:
# Mount the CSV directory and set permissions
docker run -v /host/data:/data mysql:latest
# Then in MySQL:
# LOAD DATA INFILE '/data/file.csv' ...If the file is corrupt or partially unreadable, recovery may be necessary:
For MyISAM tables (older MySQL):
# Stop MySQL
sudo systemctl stop mysql
# Run myisamchk to check and repair
sudo myisamchk -r /var/lib/mysql/mydb/mytable.MYI
# Restart MySQL
sudo systemctl start mysqlFor InnoDB tables (MySQL 5.7+):
# MySQL has built-in recovery, but if file is severely corrupt:
# 1. Stop MySQL
sudo systemctl stop mysql
# 2. Restore from backup (preferred method)
sudo cp /backup/mydb/mytable.ibd /var/lib/mysql/mydb/
sudo chown mysql:mysql /var/lib/mysql/mydb/mytable.ibd
sudo chmod 640 /var/lib/mysql/mydb/mytable.ibd
# 3. Start MySQL
sudo systemctl start mysqlFor partial corruption, use innodb_force_recovery:
# /etc/mysql/my.cnf
[mysqld]
innodb_force_recovery=3Then restart MySQL. This allows reading from corrupted InnoDB files. After dumping data, restore the backup and remove the flag.
Another process may be locking the file:
Check what processes have files open:
# Linux: list all processes accessing MySQL data directory
sudo lsof /var/lib/mysql/ | head -20
# Check for specific file
sudo lsof /var/lib/mysql/mydb/mytable.ibdCheck for stuck backup or replication processes:
# See all MySQL-related processes
ps aux | grep mysql | grep -v grep
# Kill zombie mysqld processes if needed (use with caution)
# sudo kill -9 <pid>If using NFS or network filesystem:
# Check NFS mount status and locks
showmount -a /var/lib/mysql
# Remount NFS if stale:
sudo umount /var/lib/mysql
sudo mount /var/lib/mysql
# Or check if NFS server is available
ping <nfs-server-ip>InnoDB File-Per-Table Troubleshooting:
With innodb_file_per_table enabled (MySQL 5.6+), each table has its own .ibd file. If one .ibd file is corrupted, only that table is affected. Check individual table status:
CHECK TABLE mytable;
-- If status is not OK, run:
REPAIR TABLE mytable;Cluster/Replication Specific Issues:
In MySQL Cluster or InnoDB Cluster environments, nodes synchronize data files. If a node has permission issues, it may fail to read replicated files. Ensure consistent filesystem permissions across all nodes.
Docker and Container Permissions:
Docker containers run MySQL with specific user IDs. If permissions are set on the host OS, they may not translate to the container. Use proper volume mounting and --user flags:
docker run --user mysql:mysql -v /host/data:/var/lib/mysql mysql:latestPerformance Schema for File Diagnostics:
MySQL 5.7+ includes file I/O instrumentation:
SELECT * FROM performance_schema.file_io_waits_summary_by_instance
WHERE event_name LIKE '%read%'
ORDER BY count_read DESC;Preventing EE_READ Errors:
1. Regular backups: Corrupted files are easier to recover if you have backups
2. Filesystem monitoring: Set alerts for I/O errors from dmesg/syslog
3. Regular permission audits: Ensure /var/lib/mysql stays owned by mysql:mysql
4. Monitor disk space: Keep filesystem at least 10-15% free
5. Use managed services: Cloud databases (AWS RDS, Azure Database) handle file management automatically