I am using the following query to create a CSV file
SELECT email INTO OUTFILE "mydata.csv"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM users;
But i am unable to find the mydata.csv file anywhere when i am searching through filezilla.
Any idea where this file is getting stored?
The query runs successfully without any errors! Any Help?
C:\ProgramData\MySQL\MySQL Server 5.6\data\name.csv Show activity on this post. Show activity on this post. If you don't specify an absoulte path but use something like INTO OUTFILE 'output.
INTO OUTFILE is the complement of LOAD DATA . Column values are written converted to the character set specified in the CHARACTER SET clause. If no such clause is present, values are dumped using the binary character set. In effect, there is no character set conversion.
The data directory will typically be /var/lib/mysql/ or something similar, and it will serve as the default destination for any logs that are enabled without an alternate path. The log settings are managed via a user-editable configuration file such as /etc/mysql/mysql.
MySQL may be writing the file into its own data directory, like /var/lib/mysql/<databasename>
for example. To specify the path, use a full path.
However, it must be a directory that is writable by the user account the MySQL server daemon is running under. For that reason, I'll often use /tmp
:
Specify the path you want to write to as in:
INTO OUTFILE '/tmp/mydata.csv'
And note that MySQL will write the file on the MySQL server, not on your client machine. Therefore remote connections will create output files on the remote server. See also SELECT INTO OUTFILE local ? for more details and workarounds.
A note about writing to /tmp
on a Linux system running systemd
:
Some years after originally posting this, I found myself unable to locate a file written to /tmp
via
...INTO OUTFILE '/tmp/outfile.csv'
on a MariaDB 5.5 server running Fedora Linux with systemd
. Instead of writing the file directly to /tmp/outfile.csv
as specified, that directory and file were created beneath a systemd directory in /tmp
:
/tmp/systemd-mariadb.service-XXXXXXX/tmp/outfile.csv
While the file outfile.csv
itself and the tmp/
subdirectory were both created world-writable, the systemd service directory itself has 700 permissions and is root-owned, requiring sudo
access to retrieve the file within it.
Rather than specifying the absolute path in MariaDB as /tmp/outfile.csv
and specifying it relatively as outfile.csv
, the file was written as expected into MariaDB's data directory for the currently selected database.
I suspect you are looking for the file on your client machine.
SELECT .. INTO OUTFILE
writes the file on the server machine.
Just for Example:
I have run below query in MySQL Workbench & I found my file in
SELECT * FROM `db`.`table` INTO OUTFILE 'file.csv' FIELDS TERMINATED BY ',';
D:\wamp\bin\mysql\mysql5.6.17\data\db\file.csv
You can use below example to set your file path:
SELECT * FROM `db`.`table` INTO OUTFILE 'C:\\file.csv' FIELDS TERMINATED BY ',';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With