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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ERROR 1 (HY000): Can‘t create/write to file ‘/data相关的知识,希望对你有一定的参考价值。

使用非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

[[email protected] /]$ 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;


[[email protected] 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的权限

技术分享图片








以上是关于ERROR 1 (HY000): Can‘t create/write to file ‘/data的主要内容,如果未能解决你的问题,请参考以下文章

MySQL: ERROR13(HY000):Can't get stat of

ERROR 2003 (HY000): Can't connect to MySQL server

ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)

ERROR 1010 (HY000): Error dropping database (can't rmdir './zabbix/', errno: 17)

ERROR 1010 (HY000): Error dropping database (can't rmdir './zabbix', errno: 39)

ERROR 1010 (HY000): Error dropping database (can't rmdir '.qpweb', errno: 41) 删库失败问题的解决