How do I stop “Can't create/write to file” (Errcode: 2) in MySQL?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 20:42:40

问题


I now frequently receive the error:

#1 - Can't create/write to file '/tmp/#sql_1a2_3.MYI' (Errcode: 2)

From my MySQL server. It locks out any queries or changes to data until I restart the daemon. It then fixes itself for a while and then happens again. I've tried using touch on the file inside the tmp directory with 777 permissions, and I've also tried moving the tmp directory inside of the MySQL directory (/var/lib/mysql/tmp):

MySQL Error 1 (HY000) Trouble creating file Errcode 2

Neither has worked. My tmp directory is nowhere near full with 90%+ free space, so the best answer from this question does not apply:

MySQL: Can't create/write to file '/tmp/#sql_3c6_0.MYI' (Errcode: 2) - What does it even mean?


回答1:


I've seen this being caused by a huge temporary table that was created during a complex query with many joins. Think where in your application could such a query exist and try triggering it while monitoring disk activity/available space. This is how we discovered what was going on. As a solution, you can give more space for use for temporary tables (/tmp by default), or try refactoring the query. The fact that /tmp is empty and has plenty of space when you look at it, doesn't mean it's not all getting consumed during query execution. In our case, /tmp could take all available space on disk, and it actually did during the execution of this particularly complex query, breaking with an error similar to yours because even that wasn't enough.



来源:https://stackoverflow.com/questions/13432003/how-do-i-stop-cant-create-write-to-file-errcode-2-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!