ERROR 1018 (HY000): Can’t read dir of ‘./dbname/’ (errno: 13)

The error message “ERROR 1018 (HY000): Can’t read dir of ‘./dbname/’ (errno: 13)” indicates that the MySQL server is unable to read the directory where the database files are stored, due to a file permissions issue.

Here are some steps to resolve the issue:

  1. Check the permissions of the directory and its contents using the ls -la command. The MySQL server should have read and write permissions to the directory and its contents.
  2. If the permissions are incorrect, you can change them using the chmod command. For example, if the directory is owned by the mysql user and group, you can set the appropriate permissions using the following command:
sudo chmod -R 750 /path/to/dbname/

This sets read, write, and execute permissions for the owner (mysql), read and execute permissions for the group, and no permissions for others.

  1. If the permissions are correct, check if SELinux is enabled on your system. SELinux is a security mechanism that can restrict access to files and directories based on policies. You can check if SELinux is enabled by running the command:
sestatus

If SELinux is enabled, you may need to update the policy to allow the MySQL server to access the directory. You can use the semanage command to update the policy. For example, to allow the MySQL server to access the /path/to/dbname/ directory, you can run the command:

sudo semanage fcontext -a -t mysqld_db_t "/path/to/dbname(/.*)?"
sudo restorecon -Rv /path/to/dbname/

This sets the file context for the directory and its contents to mysqld_db_t, which allows the MySQL server to access the files.

  1. If the above steps do not resolve the issue, there may be other issues such as disk errors or a corrupted file system. You may need to consult a system administrator or database expert to investigate the issue further.

Leave a Comment