Linux write file on MySQL permissions error (errcode:13) workaround

Source: Internet
Author: User
Tags parent directory

In the database select * into outfile '/home/mysql/data.sql ', MySQL also hints error:

    1. ERROR 1 (HY000): Can ' t create/write to file '/home/mysql/data.sql ' (errcode:13)



Permissions error (ERRCODE:13) workaround

1 to see if the permissions for the exported directory have been written by the MySQL user

2 If there is a multi-level directory, to ensure that the parent directory of the directory has executable permissions, if it is/root directory 700 to modify 705 otherwise write not in

3 View SeLinux There is no shutdown if not off can setsebool-a look then make sure Setsebool-p mysqld_disable_trans=1


The following is the sharing of friends:

=========================================================================


With select * into outfile '/home/mysql/data.sql ', MySQL also prompts for errors:

    1. ERROR 1 (HY000): Can ' t create/write to file '/home/mysql/data.sql ' (errcode:13)

Look at the error code, should still be the issue of permissions. Similar errors have been encountered before, if exported to the/TMP directory is not a problem. But through the "ls-l" command, confirmed that/home/mysql has been all changed to MySQL users, but also have read and write permissions, why still can not operate it?

In desperation, finally found the final solution on the Internet:

    1. # setsebool-p Mysqld_disable_trans=1

After executing the above command, restart the MySQL service and the log is finally generated. SELECT * into outfile also normal execution, is done!!!


The following excerpt from the page of the detailed introduction, specific URLs do not remember.

  1. In the Red Hat series of Linux, SELinux has limitations on what daemon can do, and MySQL's SELECT INTO outfile commands are MySQL's daemon to write file operations. Before writing a file, of course, you have permission to write files. and SELinux limits this privilege. If SELinux is turned off, this command execution is no problem.

  2. Mysql> Select User from user into outfile '/home/test.txt ';

  3. Query OK, 2 rows affected (0.02 sec)

  4. When SELinux was turned on

  5. SELinux limits the mysqld of the MySQL daemon.

  6. Mysql> Select User from user into outfile '/home/test.txt ';

  7. ERROR 1 (HY000): Can ' t create/write to file '/home/test.txt ' (errcode:13)

  8. An error has occurred that does not have permission to write.

  9. Workaround, you can turn off SELinux.

  10. Config can be found in/etc/selinux

  11. Root user,

  12. Shell>vi/etc/selinux/config

  13. # This file controls the state of the SELinux on the system.

  14. # selinux= can take one of these three values:

  15. # Enforcing-selinux security policy is enforced.

  16. # Permissive-selinux Prints warnings instead of enforcing.

  17. # Disabled-selinux is fully disabled.

  18. Selinux=enforcing

  19. Modify selinux=disabled to close selinux, this problem can be solved.

  20. But shutting down all of SELinux brings some security issues.

  21. Of course, it is also possible to give MySQL daemon permissions alone,

  22. Shell>getsebool-a can view current permissions on a series of daemons for the system.

  23. Lpd_disable_trans--off

  24. Mail_read_content--off

  25. Mailman_mail_disable_trans--off

  26. Mdadm_disable_trans--off

  27. Mozilla_read_content--off

  28. Mysqld_disable_trans--off

  29. Nagios_disable_trans--off

  30. Named_disable_trans--off

  31. Named_write_master_zones--off

  32. Nfs_export_all_ro-On

  33. NFS_EXPORT_ALL_RW-On

  34. Nfsd_disable_trans--off

  35. Nmbd_disable_trans--off

  36. Nrpe_disable_trans--off

  37. Shell>setsebool-p Mysqld_disable_trans=1

  38. Open the permissions on the MySQL daemon so

  39. Mysql> Select User from user into outfile '/home/test.txt ';

  40. There is no problem writing to the custom directory.

  41. -P indicates a permanent setting, otherwise the default value is restored after reboot.

  42. The Getsebool setsebool command has permissions under the root user.

  43. In addition to the permissions on SELinux, of course, the first thing to ensure that the directory has read and write permissions.

  44. Under Ubuntu, you can modify AppArmor (/ETC/APPARMOR.D/USR.SBIN.MYSQLD), similar to SELinux.

  45. Add/etc/squid/lists/eighties.txt W, similar.



    1. Close Mysql:service mysqld Stop

    2. Copying files: Cp-r/vqr/lib/mysql/xvdb1/

    3. Rename directory: Mv/var/lib/mysql/var/lib/mysql-backup

    4. Link files: ln-s/xvdb1/mysql/var/lib/mysql

    5. Modify Directory Permissions:

    • Chown Mysql:mysql/xvdb1/mysql-r

    • Chown-h Mysql:mysql/var/lib/mysql

Modify the content type of SELinux
    • Chcon-r-T Mysqld_db_t/xvdb1/mysql

    • Chcon-h Mysqld_db_t/var/lib/mysql

Restart Mysql:service mysqld Start

When you create a link in Linux with ln-s, such as the above Ln-s/xvdb1/mysql/var/lib/mysql, for each link, associate two objects, that is, the link itself and the file that the link points to. such as/var/lib/mysql, itself is a link, while pointing to an actual directory/xvdb1/mysql. When using Chown or Chcon on a link, the default is to modify the object that the link points to, that is,/xvdb1/mysql, not the link itself. To modify the owner or context type of the link itself, you need to add the-H parameter. So the above chown and Chcon were used two times.

Attach the error message:

110824 6:55:11 [Warning] Can ' t ' Create test File/var/lib/mysql/testemp.lower-test
110824 6:55:11 [Warning] Can ' t ' Create test File/var/lib/mysql/testemp.lower-test
/usr/libexec/mysqld:can ' t change dir to '/var/lib/mysql/' (errcode:13)


Linux write file on MySQL permissions error (errcode:13) workaround

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.