Try to use path from MySQL "secure_file_priv" system variable for batch inserting via load infile #9529
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #9528
Background:
See #9419 (comment) and #9419 (comment)
From https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_secure_file_priv
So since 5.7.6 eg the default value is
/var/lib/mysql-files
instead of being empty. This meansload data ...
only works when the file was placed within that directory. If it is not in that directory the following error might occurHowever, this applies to
LOAD DATA INFILE
. The fallbackLOAD DATA LOCAL INFILE
still seems to work even if we put the file not into the specified directory. Background for this: When using batch insert, by default we try to use the more secure wayLOAD DATA INFILE
and if this fails for some reason we try to useLOAD DATA LOCAL INFILE
if possible. Using theLOCAL
keyword means the client reads the file and sends it to the server. This fallback way usingLOCAL
is only used when there are no restrictions reopen_basedir
andsafemode
.This means by default it should still work even when we don't put the CSV file into the
secure_file_priv
directory unless there were restrictions made to the mentioned methods in which it would always fail.This patch introduces a change to trying to use the directory as specified in the
secure_file_priv
variable. If that directory actually exists, eg/var/lib/mysql-files
, and if we are allowed to write into this directory, we will put the CSV file into the specified directory and read it from there. If the setting is not specified, or if we are not allowed to write into this directory, which should be the case by default, we will use the regulartmp/assets
directory as it might still work fine via the fallback way withLOCAL
.Also to be considered is that
secure_file_priv
was introduced in MySQL 5.0.38 so for all previous versions thetmp/assets
directory will be fine anyway.