Reputation: 1179
I am trying to export result of query to a text file using outfile command ERROR 1086 (HY000): File 'test.txt' already exists is prompted when i execute it second time.
select * into outfile 'c:/test.txt' from test
I actaully want to replace the existing file.Is there any way to replace the existing file
Upvotes: 3
Views: 10367
Reputation: 13
Upvotes: 0
Reputation: 115650
From MySQL docs, SELECT ... INTO Syntax
:
The
SELECT ... INTO OUTFILE 'file_name'
form ofSELECT
writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed. As of MySQL 5.0.19, the character_set_filesystem system variable controls the interpretation of the file name.
What you could do is use a client command such as mysql -e "SELECT ..." > file_name
to generate the file.
Upvotes: 1
Reputation: 122042
From the reference - file_name cannot be an existing file
So, you should remove old file yourself, or specify another name.
Upvotes: 4