博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Can't create/write to file '/tmp/MLjnvU95' (Errcode: 13 - Permission denied)
阅读量:7077 次
发布时间:2019-06-28

本文共 4071 字,大约阅读时间需要 13 分钟。

今天一个同事反馈往一个MySQL数据库导入数据时,报ERROR 1 (HY000): Can't create/write to file '/tmp/MLjnvU95' (Errcode: 13 - Permission denied)这样的错误,如下所示:

 

 

uery OK, 0 rows affected (0.03 sec)

 

ERROR 1 (HY000): Can't create/write to file '/tmp/MLjnvU95' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/MLPzmIbJ' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/MLdpJwKm' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/MLB7FTT0' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/ML1wcUAF' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/MLYjOzPk' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/ML7gi9z0' (Errcode: 13 - Permission denied)

ERROR 1 (HY000): Can't create/write to file '/tmp/ML6nezQG' (Errcode: 13 - Permission denied)

 

 

 

个人使用source script.sql导入数据时,也是遇到这个错误,如上截图所示。从这个错误提示,可以明显看出是MySQL没有权限对/tmp进行操作,

 

 

查看系统变量tmpdir,如下所示,tmpdir变量指定路径为/tmp

 

 

mysql> show variables like 'tmpdir';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| tmpdir        | /tmp  |
+---------------+-------+
1 row in set (0.00 sec)
 
 
 
[root@mylx01 ~]# ls -lh /tmp
total 20M
-rw-rw-r--. 1 root root  20M Nov  7 12:04 cccc_user.sql
-rw-r--r--. 1 root root   57 Nov  7 02:00 percona-version-check
-rw-------. 1 root root 2.0K Nov  2 21:38 tmpP4BN3H
-rw-------. 1 root root 2.0K Oct 31 21:40 tmpusdOhs
-rw-------. 1 root root 2.0K Oct 30 21:36 tmp_WBZNO
-rw-------. 1 root root 2.1K Oct 29 21:38 tmpXcXptG
-rw-------. 1 root root 2.0K Nov  5 21:40 tmpyqSR0U
-rw-------. 1 root root 2.1K Oct 28 21:42 tmpZjNjtu

 

 

我们可以修改/tmp目录的权限; 或者修改数据库的临时目录来解决这个问题:

 

1:在配置文件my.cnf中修改数据库的临时目录,然后需要重启MySQL数据库

 

tmpdir = /var/lib/mysql

 

2:修改/tmp目录权限

 

chmod 1777 /tmp

chmod 777 /tmp

 

 

那么MySQL使用tmpdir来做什么呢?tmpdir是MySQL存临时文件的目录的路径名。如果未设置变量tmpdir,MySQL将使用系统的默认值,通常为/tmp、/var/tmp或/usr/tmp。更多详细信息,可以参考官方文档的详细介绍:

 

 

MySQL arranges that temporary files are removed if mysqld is terminated. On platforms that support it (such as Unix), this is done by unlinking the file after opening it. The disadvantage of this is that the name does not appear in directory listings and you do not see a big temporary file that fills up the file system in which the temporary file directory is located. (In such cases, lsof +L1 may be helpful in identifying large files associated with mysqld.)

When sorting (ORDER BY or GROUP BY), MySQL normally uses one or two temporary files. The maximum disk space required is determined by the following expression:

 

(length of what is sorted + sizeof(row pointer))* number of matched rows

 * 2

 

The row pointer size is usually four bytes, but may grow in the future for really big tables.

For some SELECT queries, MySQL also creates temporary SQL tables. These are not hidden and have names of the form SQL_*.

DDL operations that rebuild the table and are not performed online using the ALGORITHM=INPLACE technique create a temporary copy of the original table in the same directory as the original table.

 

Online DDL operations may use temporary log files for recording concurrent DML, temporary sort files when creating an index, and temporary intermediate tables files when rebuilding the table. For more information, see Section 15.12.3, “Online DDL Space Requirements”.

 

InnoDB user-created temporary tables and on-disk internal temporary tables are created in a temporary tablespace file named ibtmp1 in the MySQL data directory. For more information, see Section 15.6.3.5, “Temporary Tablespaces”.

 

 

 

MySQL会以隐含方式创建所有的临时文件。这样,就能确保中止mysqld时会删除所有临时文件。使用隐含文件的缺点在于,在临时文件目录所在的位置中,看不到占用了文件系统的大临时文件。

 

进行排序时(ORDER BYGROUP BY),MySQL通常会使用1个或多个临时文件。所需的最大磁盘空间由下述表达式决定:

 

(length of what is sorted + sizeof(row pointer))

 

* number of matched rows

 

* 2

 

row pointer(行指针)的大小通常是4字节,但在以后,对于大的表,该值可能会增加。

 

对于某些SELECT查询,MySQL还会创建临时SQL表。它们不是隐含表,并具有SQL_*形式的名称。

 

ALTER TABLE会在与原始表目录相同的目录下创建临时表。

 

如果内存临时表超出了限制,MySQL就会自动地把它转化为基于磁盘的MyISAM表,存储在指定的tmpdir目录下。

 

 

 

 

 

参考资料:

 

https://dev.mysql.com/doc/refman/8.0/en/temporary-files.html

转载地址:http://vdcml.baihongyu.com/

你可能感兴趣的文章
《CCNP TSHOOT 300-135认证考试指南》——6.9节三层EtherChannel故障工单
查看>>
Google AI 发明了自己的防窃听加密算法
查看>>
Edge 浏览器新 Bug:SmartScreen 界面或被用来欺诈
查看>>
SlimerJS —— 基于Firefox的网页自动化测试工具
查看>>
《Cisco BGP-4 命令与配置手册》——1-3 aggregate-address address mask
查看>>
《部署IPv6网络(修订版)》一1.2 QoS服务
查看>>
Chrome力推HTTPS:HTTP网站被标注为不安全
查看>>
《Adobe InDesign CS6中文版经典教程》—第2课2.3节在工作时执行印前检查
查看>>
微软发 Edge 宣传视频:更快更安全的浏览器
查看>>
如何看待开发人员转型做产品经理?
查看>>
《智能数据时代:企业大数据战略与实战》一1.2 大数据如何发掘价值
查看>>
Zookeeper的安装部署,zookeeper参数配置说明,集群搭建,查看集群状态
查看>>
《Java多线程编程核心技术》——2.1节synchronized同步方法
查看>>
《Adobe Illustrator CS6中文版经典教程(彩色版)》—第1课1.6节使用面板
查看>>
《深入解析IPv6(第3版)》——2.8 使用Windows PowerShell来查看IPv6配置信息
查看>>
阿里巴巴企业诚信体系 .xin域名解读(阿里之声)
查看>>
利用物联网发动 DDoS 攻击的恶意程序源代码公开
查看>>
《基于ArcGIS的Python编程秘笈(第2版)》——1.2 ArcGIS Python窗口的使用
查看>>
《策略驱动型数据中心——ACI技术详解》一1.3 数据中心设计
查看>>
Raspberry Pi 树莓派获得 OpenGL 支持
查看>>