In the database select * into outfile '/home/mysql/data.sql ', MySQL also hints error:
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:
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:
# 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.
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.
Mysql> Select User from user into outfile '/home/test.txt ';
Query OK, 2 rows affected (0.02 sec)
When SELinux was turned on
SELinux limits the mysqld of the MySQL daemon.
Mysql> Select User from user into outfile '/home/test.txt ';
ERROR 1 (HY000): Can ' t create/write to file '/home/test.txt ' (errcode:13)
An error has occurred that does not have permission to write.
Workaround, you can turn off SELinux.
Config can be found in/etc/selinux
Root user,
Shell>vi/etc/selinux/config
# This file controls the state of the SELinux on the system.
# selinux= can take one of these three values:
# Enforcing-selinux security policy is enforced.
# Permissive-selinux Prints warnings instead of enforcing.
# Disabled-selinux is fully disabled.
Selinux=enforcing
Modify selinux=disabled to close selinux, this problem can be solved.
But shutting down all of SELinux brings some security issues.
Of course, it is also possible to give MySQL daemon permissions alone,
Shell>getsebool-a can view current permissions on a series of daemons for the system.
Lpd_disable_trans--off
Mail_read_content--off
Mailman_mail_disable_trans--off
Mdadm_disable_trans--off
Mozilla_read_content--off
Mysqld_disable_trans--off
Nagios_disable_trans--off
Named_disable_trans--off
Named_write_master_zones--off
Nfs_export_all_ro-On
NFS_EXPORT_ALL_RW-On
Nfsd_disable_trans--off
Nmbd_disable_trans--off
Nrpe_disable_trans--off
Shell>setsebool-p Mysqld_disable_trans=1
Open the permissions on the MySQL daemon so
Mysql> Select User from user into outfile '/home/test.txt ';
There is no problem writing to the custom directory.
-P indicates a permanent setting, otherwise the default value is restored after reboot.
The Getsebool setsebool command has permissions under the root user.
In addition to the permissions on SELinux, of course, the first thing to ensure that the directory has read and write permissions.
Under Ubuntu, you can modify AppArmor (/ETC/APPARMOR.D/USR.SBIN.MYSQLD), similar to SELinux.
Add/etc/squid/lists/eighties.txt W, similar.
Close Mysql:service mysqld Stop
Copying files: Cp-r/vqr/lib/mysql/xvdb1/
Rename directory: Mv/var/lib/mysql/var/lib/mysql-backup
Link files: ln-s/xvdb1/mysql/var/lib/mysql
Modify Directory Permissions:
Modify the content type of SELinux
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