Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.8Mb
PDF (A4) - 37.8Mb
PDF (RPM) - 36.4Mb
HTML Download (TGZ) - 9.8Mb
HTML Download (Zip) - 9.9Mb
HTML Download (RPM) - 8.6Mb
Man Pages (TGZ) - 209.5Kb
Man Pages (Zip) - 318.7Kb
Info (Gzip) - 3.5Mb
Info (Zip) - 3.5Mb
Excerpts from this Manual

B.5.2.12 Can't create/write to file

If you get an error of the following type for some queries, it means that MySQL cannot create a temporary file for the result set in the temporary directory:

Can't create/write to file '\\sqla3fe_0.ism'.

The preceding error is a typical message for Windows; the Unix message is similar.

One fix is to start mysqld with the --tmpdir option or to add the option to the [mysqld] section of your option file. For example, to specify a directory of C:\temp, use these lines:


The C:\temp directory must exist and have sufficient space for the MySQL server to write to. See Section 4.2.6, “Using Option Files”.

Another cause of this error can be permissions issues. Make sure that the MySQL server can write to the tmpdir directory.

Check also the error code that you get with perror. One reason the server cannot write to a table is that the file system is full:

shell> perror 28
OS error code  28:  No space left on device

If you get an error of the following type during startup, it indicates that the file system or directory used for storing data files is write protected. Provided that the write error is to a test file, the error is not serious and can be safely ignored.

Can't create test file /usr/local/mysql/data/master.lower-test

User Comments
  Posted by Jes Nielsen on April 11, 2006
Please notice that antivirus programs may sporadically lock MySQL temporary files, and make the server to throw an “Can't create/write to file '/tmp/#sql_3a5_0.MYI' (Errcode: 13)”. I fixed the problem by excluding the MySQL temporary directory from antivirus scanning.
  Posted by Meg Valentine on April 12, 2007
i fixed the problem by only including the fields that i needed in my select statement rather than *

ie i changed SELECT *

to SELECT FirstName, LastName
  Posted by Jon Webb on April 23, 2007
ERROR: Can't read/write to file...
i keep forgetting why it fails for me (i use windows and *nix), so heres what needs to be checked:
- antivirus interference (never caused me errors)
- use 'somefieldname' instead of * (never caused me errors)
- permissions (i've forgotten to give 'Everyone' Read & Write perms on windows, chmod 777 on *nix)
- give MySQL user FILE perms (CREATE USER MyDBconnecter...with FILE perms)
- $myroot=str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']);
(this last one often trips me up: the \ causes trouble on windows)

Hope this helps others,
  Posted by Miha Novak on October 16, 2007
Preconditions: arch 64bit,kde
Problem: on mysqld restart there was the following error:
./usr/sbin/mysqld: Can't create/write to file '/tmp/ibg6qcGT' (Errcode: 13)
071017 1:08:58 InnoDB: Error: unable to create temporary file; errno: 13
071017 1:08:58 [ERROR] bdb: /var/lib/mysql: Permission denied
071017 1:08:58 [ERROR] bdb: /var/lib/mysql/log.0000000001: Permission denied
071017 1:08:58 [ERROR] bdb: PANIC: Permission denied
071017 1:08:58 [ERROR] bdb: PANIC: DB_RUNRECOVERY: Fatal error, run database recovery
071017 1:08:58 [ERROR] bdb: fatal region error detected; run recovery
071017 1:08:58 [ERROR] bdb: /var/lib/mysql: Permission denied
071017 1:08:58 [ERROR] Can't start server : Bind on unix socket: Permission denied
071017 1:08:58 [ERROR] Do you already have another mysqld server running on socket: /tmp/mysql.sock ?
071017 1:08:58 [ERROR] Aborting
I tried many things and read many thing but at the end I just went to the KUser (User Manager in kde),select mysql user and ticked into option Account Disabled and after it worked. It seems that that tick somehow refreshed the permissions.
  Posted by Jagdeep Singh on March 21, 2009
Turning "off" the scanning of windows/temp folder in the anti-virus resolved the issue for me.
I was not getting the issue for all the queries, but for some of them and that too not always. The error occurred when a lot of temporary MYI files were being created, and the anti-virus 'locked' the folder for scanning, before it could be written by next query result.

  Posted by Mike Tee on October 15, 2010
If you are running Microsoft Security Essentials on Windows, here's a way to fix the issue. Go to Settings > Excluded Files & Locations. Click on Add, and browser to the MySQL folder.

On my computer, it's c:\wamp\bin\mysql

Click OK, and Save Changes.
  Posted by Austin Swinney on January 5, 2011
On linux, Security-Enhanced Linux (SELinux) might be enabled.

`man selinux` or google "disable selinux"

  Posted by Dong Guo on December 8, 2011
If you are using RHEL or CentOS, it may be caused by SELinux firewall settings.
  Posted by curtis pastore on January 11, 2012
Here is a good link that really helped me out with SE linux
  Posted by don le quy on May 5, 2013
in Mac OS, if you made changes to folder temp (delete, recreate), the owner of folder "temp" should be changed, so mysql can not make changes with it

we have to change owner of folder "temp" to "nobody"

open terminal and enter without ""

"sudo chown nobody /applications/xampp/xamppfiles/temp"
then enter your computer's password

/applications/xampp/xamppfiles/temp is link to your folder "temp"
  Posted by Karthick Subramanian on August 19, 2016
For CentOS/RHEL (7), this is due to SElinux.

Connect to mysql:

MariaDB [(none)]> show variables like '%dir%';
| Variable_name | Value |
| aria_sync_log_dir | NEWFILE |
| basedir | /usr/ |
| binlog_direct_non_transactional_updates | OFF |
| character_sets_dir | /usr/share/mysql/charsets/ |
| datadir | /var/lib/mysql/ |
| ignore_db_dirs | |
| innodb_data_home_dir | |
| innodb_log_arch_dir | ./ |
| innodb_log_group_home_dir | ./ |
| innodb_max_dirty_pages_pct | 50.000000 |
| innodb_max_dirty_pages_pct_lwm | 0.001000 |
| innodb_tmpdir | |
| innodb_undo_directory | . |
| lc_messages_dir | |
| plugin_dir | /usr/lib64/mysql/plugin/ |
| slave_load_tmpdir | /tmp |
| tmpdir | /tmp |
| wsrep_data_home_dir | /var/lib/mysql/ |
| wsrep_dirty_reads | OFF |

Once you locate the tmpdir location(/tmp in my example), you can go back to shell prompt:

# ls -lZ /tmp
-rw-------. root root system_u:object_r:rpm_tmpfs_t:s0 yum_save_tx.2016-08-18.06-35.AdDY3e.yumtx

# semanage fcontext -a -t mysqld_db_t "/tmp(/.*)?"

# grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local
/usr/share/cracklib(/.*)? system_u:object_r:mysqld_etc_t:s0
/tmp(/.*)? system_u:object_r:mysqld_db_t:s0

# restorecon -R -v /tmp
restorecon reset /tmp context system_u:object_r:tmpfs_t:s0->system_u:object_r:tmp_t:s0
restorecon reset /tmp/yum_save_tx.2016-08-18.06-35.AdDY3e.yumtx context system_u:object_r:rpm_tmpfs_t:s0->system_u:object_r:mysqld_db_t:s0

# systemctl restart mariadb

# ls -lZ /tmp
-rw-------. root root system_u:object_r:mysqld_db_t:s0 yum_save_tx.2016-08-18.06-35.AdDY3e.yumtx

That's it!

Note: Change the MariaDB to mysql, syntax/command is same.
  Posted by John Little on February 26, 2018
On Ubuntu, apparmor can cause this error. (It has a similar role as SELinux.)

The Ubuntu apparmor defaults for mysql limit the directories the mysqld process can write to.


If the world can't access your mysql so you don't care,

sudo aa-complain /usr/sbin/mysqld

puts mysqld in complain mode, a message in a system log only, rather than enforce mode.
Sign Up Login You must be logged in to post a comment.