MySQL 错误代码 13 , SELECT INTO OUTFILE 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14416379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Errcode 13 , SELECT INTO OUTFILE issue
提问by user1990170
I'm trying to understand the reason why I keep experiencing problems while using INTO OUTFILE command.
我试图了解为什么我在使用 INTO OUTFILE 命令时一直遇到问题。
I always get this erroro:
我总是得到这个错误:
ERROR 1 (HY000): Can't create/write to file '/var/www/p1.txt' (Errcode: 13)
SELECT password FROM mysql.user WHERE user='root' INTO OUTFILE '/var/www/p1.txt';
Useful details:
有用的细节:
web application : DVWA (localhost) (for study purposes)
Server: Apache/2.2.14 (Ubuntu) - PHP/5.3.2
MySQL version 5.1.63
Operating system Linux Backtrack 5r3.
Web 应用程序:DVWA(本地主机)(用于学习目的)
服务器:Apache/2.2.14 (Ubuntu) - PHP/5.3.2
MySQL 版本 5.1.63
操作系统 Linux Backtrack 5r3。
I'm running the command as root. Also, I can freely create folders or files in /var/www/
我以 root 身份运行命令。此外,我可以在 /var/www/ 中自由创建文件夹或文件
Errcode 13 I know it means permission denied, but what should I do in order to fix the problem?
Errcode 13 我知道这意味着权限被拒绝,但我应该怎么做才能解决问题?
Any help will be highly appreciated.
任何帮助将不胜感激。
采纳答案by Vorsprung
chown /var/www to the user trying to write the file, or chmod 777 /var/www
chown /var/www 给试图写入文件的用户,或 chmod 777 /var/www
this is probably not a secure way of doing it, you might like to consider putting the file elsewhere
这可能不是一种安全的方法,您可能会考虑将文件放在其他地方
回答by Joachim Isaksson
Even if you're logged in as root into MySQL, the file write will be performed as the user running the actual MySQL daemon.
即使您以 root 身份登录 MySQL,文件写入也会以运行实际 MySQL 守护程序的用户身份执行。
In other words, you should check which user runs mysqld, and give write permission to the directory for that user.
换句话说,您应该检查哪个用户运行 mysqld,并为该用户授予对该目录的写权限。
回答by tony gil
you must alter the permissions for user mysqld
. start by running the following command sudo aa-status
to check your user status and authorized directories. if you want to change permissions, edit /etc/apparmor.d/usr.sbin.mysqld
and insert the directories you want.
您必须更改 user 的权限mysqld
。首先运行以下命令sudo aa-status
来检查您的用户状态和授权目录。如果要更改权限,请编辑/etc/apparmor.d/usr.sbin.mysqld
并插入所需的目录。
you must then restart apparmor sudo /etc/init.d/apparmor restart
然后你必须重新启动apparmor sudo /etc/init.d/apparmor restart
回答by Petrus
Although this post is quite old, in 2018 this problem is still there. I spent a couple of hours banging my head in this maze.
虽然这个帖子比较老了,但是2018年这个问题依然存在。我花了几个小时在这个迷宫中敲打我的头。
Server version: 5.7.24 MySQL Community Server (GPL) running on Ubuntu 14.04
服务器版本:5.7.24 MySQL Community Server (GPL) 在 Ubuntu 14.04 上运行
To allow MySql to SELECT INTO OUTFILE requires to set MySQL's
secure-file-priv
option in your configuration. Append the following 2 lines to/etc/mysql/mysql.conf
:[mysqld] # allow INTO OUTFILE file and LOAD DATA INFILE to this directory secure_file_priv=/usr/share/mysql-files
/usr/share/mysql-files
is the directory where my files will be stored. I created it doing:sudo su cd /usr/share mkdir mysql-files chown mysql:mysql mysql-files chmod a+rw mysql-files
要允许 MySql SELECT INTO OUTFILE 需要
secure-file-priv
在您的配置中设置 MySQL 的选项。将以下 2 行附加到/etc/mysql/mysql.conf
:[mysqld] # allow INTO OUTFILE file and LOAD DATA INFILE to this directory secure_file_priv=/usr/share/mysql-files
/usr/share/mysql-files
是我的文件将被存储的目录。我创建它做:sudo su cd /usr/share mkdir mysql-files chown mysql:mysql mysql-files chmod a+rw mysql-files
Change /usr/share/mysql-files
for whatever you prefer, but avoid to use the /tmp
directory!
更改/usr/share/mysql-files
为您喜欢的任何内容,但避免使用/tmp
目录!
Why?Because, at next time you'll be rebooting, the /tmp
directory is happily erased including your precious mysql-files sub-directory. The mysql service then chokes and it won't start, leading to wierd errors with cryptics messages.
为什么?因为,下次您重新启动时,该/tmp
目录会被愉快地删除,包括您宝贵的 mysql-files 子目录。然后 mysql 服务窒息并且无法启动,从而导致出现带有神秘消息的奇怪错误。
restart mysql and check:
sudo su service mysql restart mysql mysql> SHOW VARIABLES LIKE "%secure%"; +--------------------------+-------------------------+ | Variable_name | Value | +--------------------------+-------------------------+ | require_secure_transport | OFF | | secure_auth | ON | | secure_file_priv | /usr/share/mysql-files/ | +--------------------------+-------------------------+ 3 rows in set (0.07 sec) mysql> quit Bye
You are not done, yet!
重新启动 mysql 并检查:
sudo su service mysql restart mysql mysql> SHOW VARIABLES LIKE "%secure%"; +--------------------------+-------------------------+ | Variable_name | Value | +--------------------------+-------------------------+ | require_secure_transport | OFF | | secure_auth | ON | | secure_file_priv | /usr/share/mysql-files/ | +--------------------------+-------------------------+ 3 rows in set (0.07 sec) mysql> quit Bye
你还没有完成!
There is a troll by the name of apparmor
who will ruines your project.
Edit the file /etc/apparmor/local/usr/sbin/mysqld
and append the
following 2 lines -- don't forget the ending commas:
有一个巨魔的名字是apparmor
谁会毁了你的项目。编辑文件/etc/apparmor/local/usr/sbin/mysqld
并附加以下两行——不要忘记结尾的逗号:
/usr/share/mysql-files rw,
/usr/share/mysql-files/** rw,
save it, and reparse:
保存并重新解析:
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld
That should make it.
那应该可以。
回答by Kris Roofe
Check the user of mysqld with,
检查 mysqld 的用户,
ps -aef | grep mysql
mysql 9355 9102 0 Aug24 ? 21:53:25 /usr/libexec/mysqld
Check wiich group mysql belong to with,
检查 wiich 组 mysql 属于 with,
groups mysql
mysql : mysql www
Then write the file under path which belong to mysql or have write permission for group www and mysql. For example, test under has write permission to group www.
然后将文件写在属于mysql或对www和mysql组有写权限的路径下。例如,test under 具有对 www 组的写权限。
ll /data/
drwxrwxr-x 2 www www 4096 Dec 9 19:31 test
Then execute mysql mysql -u root -p -e 'use sc_test; select file_path from sc_files INTO OUTFILE "/data/test/paths.txt";'
然后执行mysql mysql -u root -p -e 'use sc_test; select file_path from sc_files INTO OUTFILE "/data/test/paths.txt";'
回答by Ellert van Koperen
On centos the selinux thing is playing not-nice.
在 centos 上,selinux 的功能不太好。
$ getenforce
Enforcing
$ setenforce 0
Permissive
Now this is crude, but worked for me (until reboot, then it switches back on). If this temporary measure works, you need to google for how to configure selinux properly.
现在这很粗糙,但对我有用(直到重新启动,然后重新打开)。如果这个临时措施有效,你需要谷歌一下如何正确配置selinux。