MySQL File Access

June 4, 2018

MySQL out of the box doesn’t permit access to the local file system e.g. for table import or export operations. Quickest fix for this that I found was to run the server from the command line as follows:

mysqld --secure-file-priv=/Users/me/tmp

I can then use statements such as

load data infile '~/tmp/data.csv' fields terminated by ',' 
ignore 1 lines (field1,field2,@field3) set field3=somefunction(@field3);

or

select field1,field2,someotherfunction(field3) from sometable into
outfile '~/tmp/outdata.dsv' terminated by '|';
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: