ERROR 1 (HY000): Can't create/write to file '/data

2019-03-15 18:01:44 浏览数 (1)

使用非DBA用户进行load data 操作,发现报错。

MariaDB [temp_archive]> select * from t1 into outfile '/data/test.sql';

ERROR 1 (HY000): Can't create/write to file '/data/test.sql' (Errcode: 13 "Permission denied")

提示报错。

报错原因权限不足。

分析:

   权限有系统权限和数据库权限。

/data 目录权限 chown -R mysql:mysql /data/

实验1:操作系统权限

创建hy用户,使用root账户操作,文件保存目录/data/:

useradd -u 1100 hy

password hy

su hy

[hy@XHY005116 /]$ mysql

MariaDB [(none)]> use test

Database changed

MariaDB [test]> select * from t111 into outfile '/data/t111.sql';

Query OK, 1 row affected (0.00 sec)

MariaDB [test]> create table t112 like t111;

Query OK, 0 rows affected (0.08 sec)

MariaDB [test]> load data infile '/data/t111.sql' into table t112;

Query OK, 1 row affected (0.02 sec)                  

Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

  • 文件保存目录/

MariaDB [test]> select * from t111 into outfile '/t111.sql';

ERROR 1 (HY000): Can't create/write to file '/t111.sql' (Errcode: 13 "Permission denied")

  • 报错:权限不足,此处可以分析出系统权限不足,导致报错。

实验2:

hy用户登录ya,ya账户读写权限,文件保存目录 /data/。

MariaDB [test]> select * from t100 into outfile '/data/t100.sql';

ERROR 1045 (28000): Access denied for user 'ya'@'192.168.%' (using password: YES)

  • 使用root用户导出的文件,使用ya用户导入

MariaDB [test]> load data infile '/data/t100.sql' into table t101;

ERROR 1045 (28000): Access denied for user 'ya'@'192.168.%' (using password: YES)

均报错:判断是数据库权限问题。

尝试授权file权限。

MariaDB [(none)]> grant file on *.* to 'ya'@'192.168.%';

MariaDB [(none)]> flush privileges;

[hy@XHY005116 data]$ mysql -uya -p123456 -h192.168.5.116

MariaDB [test]> select * from t101 into outfile '/data/t101.sql';

MariaDB [test]> load data infile '/data/t101.sql' into table t102;

Query OK, 6 rows affected (0.02 sec)          

成功:

文件保存目录:/

MariaDB [test]> select * from t101 into outfile '/t101.sql';

ERROR 1 (HY000): Can't create/write to file '/t101.sql' (Errcode: 13 "Permission denied

报错:权限问题。

  • 结合:上两个实验可以得出“(Errcode: 13 "Permission denied” 错误是和操作系统目录有关。

对应mysql的权限

©著作权归作者所有:来自51CTO博客作者杨凯悦的原创作品,如需转载,请注明出处,否则将追究法律责任

0 人点赞