When you’re working with file-based operations in MySQL, such as loading data from a text file, you might encounter Error 1085. This error indicates that MySQL cannot read the specified file because it is not located in the database directory or does not have the necessary read permissions for all users. This guide will provide you with practical solutions to diagnose and resolve this issue, ensuring that your file-based data operations run smoothly.
Understanding Error 1085 (ER_TEXTFILE_NOT_READABLE)
MySQL Error 1085 is triggered when the server attempts to read a text file for a database operation and finds that it either doesn’t have the right permissions or the file is not in an expected location. This commonly occurs during LOAD DATA INFILE
operations.
Diagnosing the Problem
- Check File Location: Verify that the file you’re trying to load is located in the database directory, which is typically
/var/lib/mysql/
on Linux systems. - Review File Permissions: Make sure the file has the correct permissions set. It should be readable by the MySQL server process.
- Confirm File Ownership: The file should be owned by the user running the MySQL server, often ‘mysql’ on Linux systems.
Fixing the Error
Move File to Database Directory
If the file is not in the database directory, you can move it there:
sudo mv /path/to/your/file.txt /var/lib/mysql/db_name/
Replace /path/to/your/file.txt
with the path to your file and db_name
with the name of your database.
Update File Permissions
To update the file permissions so that it’s readable by all users, you can use the chmod
command:
sudo chmod 644 /path/to/your/file.txt
This sets the file to be readable by all users, which includes the MySQL server process.
Change File Ownership
If the file is not owned by the MySQL user, change its ownership with the chown
command:
sudo chown mysql:mysql /path/to/your/file.txt
This sets the MySQL user as the owner of the file.
Use LOCAL Keyword
If you cannot move the file to the database directory or change its permissions, you can use the LOCAL
keyword with the LOAD DATA INFILE
command. This allows MySQL to read the file from the client’s local file system:
LOAD DATA LOCAL INFILE '/path/to/your/file.txt' INTO TABLE your_table;
Check AppArmor or SELinux Policies
If you’re using AppArmor (on Ubuntu) or SELinux (on CentOS or RHEL), make sure that the security policies allow MySQL to read from the directory where your file is located.
Conclusion
MySQL Error 1085 occurs when the server cannot read a specified text file due to permissions or location issues. By ensuring that the file is in the correct directory, setting the appropriate permissions, and adjusting ownership as necessary, you can resolve this error. Remember to consider security policies that may be in place on your server, and use the LOCAL
keyword as a workaround if needed. With these steps, your MySQL server will be able to read text files for data operations without any hiccups.