Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use path from MySQL "secure_file_priv" system variable for batch inserting via load infile #9529

Merged
merged 1 commit into from Jan 20, 2016

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Jan 15, 2016

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

If set to the name of a directory, the server limits import and export operations to work only with files in that directory. ...

... Before MySQL 5.7.6, this variable is empty by default. As of 5.7.6, the default value is platform specific ...

So since 5.7.6 eg the default value is /var/lib/mysql-files instead of being empty. This means load data ... only works when the file was placed within that directory. If it is not in that directory the following error might occur

SQLSTATE[HY000]: General error: 1290 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

However, this applies to LOAD DATA INFILE. The fallback LOAD 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 way LOAD DATA INFILE and if this fails for some reason we try to use LOAD DATA LOCAL INFILE if possible. Using the LOCAL keyword means the client reads the file and sends it to the server. This fallback way using LOCAL is only used when there are no restrictions re open_basedir and safemode.

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 regular tmp/assets directory as it might still work fine via the fallback way with LOCAL.

Also to be considered is that secure_file_priv was introduced in MySQL 5.0.38 so for all previous versions the tmp/assets directory will be fine anyway.

@tsteur tsteur added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Jan 15, 2016
@tsteur tsteur added this to the 2.16.0 milestone Jan 15, 2016
// in this case tableInsertBatch might still work
}

if (empty($path) || !is_dir($path) || !is_writable($path)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should also check is_readable as a folder can be writable yet not readable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but only MySQL would need to be able to read from it or not?

@oraclerob
Copy link

This description looks good.

mattab pushed a commit that referenced this pull request Jan 20, 2016
Try to use path from MySQL "secure_file_priv" system variable for batch inserting via load infile
@mattab mattab merged commit b6ad18a into master Jan 20, 2016
@mattab mattab deleted the 9419_3 branch January 21, 2016 06:08
@nisdis
Copy link

nisdis commented Apr 12, 2017

According to the piwik docs
https://piwik.org/faq/troubleshooting/#faq_194

This is what worked for me:

update to the latest PHP version, or use the mysqli client (there are some known bugs with older PDO clients for mysql)
and/or switch the client to adapter=MYSQLI in the config/config.ini.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants