'Can't create/write to file 'xxxx.txt' (Errcode: 13 - Permission denied)
mysql> \T abc.txt
./mysql: Can't create/write to file 'abc.txt' (Errcode: 13 - Permission denied)
Error logging to file 'logPremiereQueries.txt'
I meet the same problem when I use Windows 8. I solve it by running cmd (MySQL 5.6 Command Line Client) as administrator. And then I could easily find the position of abc.txt. However, in Mac OS X, I do not know how to change the permission. And if log to file successfully, where to find this 'abc.txt'? Any ideas? Thank you very much!
Solution 1:[1]
Just leaving this here for the future...
If you are using Windows, open services. Right click on mysql service, select properties. In the properties window select Log On tab then Log on as: Local System account.
If you are ready, restart the service and you can select into outfile anywhere where you have permission to write.
Solution 2:[2]
If you don't provide a specific path for a file when using tee (\T) command mysql will try to create or append to the file in the current working directory (directory from which mysql has been started)
The error is self explanatory - you just don't have permissions to write a file in a current working directory.
If you don't know (which is strange) what is your current working directory you can execute system pwd command from mysql command prompt
mysql> \! pwd
Now to resolve the problem either:
change your working directory in terminal to the one that you have write permissions on (e.g. your home directory) and then start mysql client
$ cd ~ $ mysql -uusername -p dbnamein mysql prompt when using
tee (\T)command specify a valid path to the directory that you have write permissions on e.g.mysql> \T /Users/username/abc.txt
Solution 3:[3]
please to see -> https://dev.mysql.com/doc/refman/5.0/en/cannot-create.html
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
Solution 4:[4]
I have faced this problem and solved this bug.
SELECT * FROM mahitab INTO OUTFILE '/var/lib/mysql-files/mahitab.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINE;
ERROR 1 (HY000): Can't create/write to file '/var/lib/mysql-files/mahitab.csv' (Errcode: 13 - Permission denied)
We have to give the permission to
[root@localhost tmp]# chmod 1777 /var/lib/mysql-files/
Solution 5:[5]
I work with windows 10 and, I also faced this problem when I used 'TEE'/'tee'/'\T' command. I solved it using these steps. First, we have to create a text file in a notepad and save it. Then copy the file path and use it with the tee command. Don't forget to convert the backslashes to forward slashes. Ex: TEE C:/Users/User-PC/Desktop/sqlfile.txt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gerg? Czuczor |
| Solution 2 | peterm |
| Solution 3 | user3401459 |
| Solution 4 | Dheeraj Vepakomma |
| Solution 5 | Supeshala Hansini |
