What UID is used by MySQL when a query is made? - mysql

I'm trying to read a file through MySQL's load_file command. But the result returned is Null and no error has occured in my query.
Since the file I'm trying to read is www-data protected, i'm wondering what my identity is in the server, if it isn't www-data.
It's pretty strange since I can use load_file to read /etc/passwd file.

The UID doesn't matter. The LOAD_FILE function will only read files that are world-readable. From the documentation:
The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.
So you can't use this to read a file that's only readable by the www-data user. You can use it with /etc/passwd because anyone can read that file.

Related

cant make local database because Error: FIle/etc/my.cnf doesnt exist

i want to make local database on workbench and when i configure local management it was said
Check if /etc/my.cnf can be accessed
Operation failed: File /etc/my.cnf doesn't exist
so i've used this option on my terminal
sudo cp my-huge.cnf /etc/my.cn
and it was said
cp: cannot stat 'my-huge.cnf': No such file or directory
when i check my support-files, it was not any single of my.cnf files, so i just confused why my mysql dont have any my.cnf files.
mysql doesn't include .cnf files because the default configuration is reasonably sane.
When my-huge.cnf existed it was written in the year ~2000 and its huge definition didn't change ever. (~4 cpus and ~1G ram - ha, there was even a huge-4G.cnf file for when "huge" wasn't enough)
If something is requiring /etc/my.cnf to exist, create it as an empty file (e.g. touch /etc/my.cnf).

Does the function 'load_file()' in MySQL must use path from the server?

This is the current only path I can use load_file() function in MySQL:
C:\ProgramData\MySQL\MySQL Server 8.0\Uploads
Can I not attach any other file from any other path?
Because I am able to attach BLOB file attachment only from the path mentioned above. But attaching a path from a \Desktop or else where.. shows values as null.
Can this be altered? If so, how?
https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_load-file
Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.

Can't find 'secure_file_priv' variable in my.cnf

I'm using mysql, and I want to enable saving queries to text files in any location. Currently, when I run the mysql command:
show variables like 'secure_file_priv';
I receive the value for 'secure_file_priv':
/var/lib/mysql-files/
I am able to save my queries to files in this location but nowhere else of course. (I'm also having trouble accessing this folder, even when I try to access it as root)
I found my 'my.cnf' file in '/etc/my.cnf', but it doesn't contain the variable 'secure_file_priv'!
I added it in myself as:
secure_file_priv=""
But this didn't do anything.
I also tried changing it through the mysql terminal, but it is a readonly variable, so I wasn't able to.
Where is this variable located and how can I change it to allow me to write the results of queries to files anywhere?

File not found in MySQL data directory

I am trying to load an XML file into a table on my localhost MySQL server. Per MySQL 5.6 refman page I have my file loaded in the Data directory however I keep getting the error that my file is not found. I executed the SHOW VARIABLES WHERE Variable_Name LIKE "%dir" command and found where my data dictionary is located (C:\ProgramData\MySQL\MySQL Server 5.6\Data) and it's where I put my xml file but still get the same error:
mysql> USE test
Database changed
mysql> LOAD XML LOCAL INFILE 'testXML.xml'
-> INTO TABLE testxml
-> ROWS IDENTIFIED BY '<Data>';
ERROR 2 (HY000): File 'testXML.xml' not found (Errcode: 2 - No such file
or directory)
Any suggestions/direction would be appreciated. Thanks.
I remember having such a problem once and the problem was the spaces in the path name.
If really the file is at the right place and a file not found occur, I would highly suspect that the folder name 'MySQL Server 5.6' is the problem. You can validate this easily, put the file in another folder instead of the data dir and try adding/removing spaces to the folder name and see if it works.
An other possibility is that your folder is located in an Admin directory and that you don't have right to access.

What is the 'Query' MySQL data file used for?

I am having some real difficulties finding out exactly what a certain file in the MySQL data directory is used for. (Using Google with its file name is pointless!)
Basically, I need to create some space on the drive that hosts all MySQL data and have noticed a file almost 16GB in size!!
I cant see any reference to a Query file in my config file nor can I match its size up to that of any log files, etc (in case its a log file missing the .log extension). I'm totally stumped!
I would like to know what this file is and how to reduce its size if at all possible?
Thanks in advance for your assistance!
That could be the general query log (I said "could" because the name can be configured by yourself). Look in your my.ini for an entry
log=/path/to/query
Or start the MySQL Administrator, goto "Startup Variables->Log Files" and look for "Query Logfile"
That file is completely unnessasary for your server to run (if you confirmed that the entry log=... exists in your config.
It is just good for debugging.
Try stopping your mysql server, delete it and restart your server again. The file will be recreated.
I also noticed that the slow-query-log ("diamond-slow-log") is large, too.
That file only logs queries that take longer than x seconds (2 by default). That file can be deleted or deactivated, too. But I would keep it since it contains queries that could easily be optimized with an extra index.
Update
there is another way, to confirm that this is the general query log.
Download a windows port of the tail unix command. E.g. this one http://tailforwin32.sourceforge.net/
I often use this on my dev machine to see what is goning on.
Open a shell (cmd.exe) and navigate the folder where that file exists.
Then type
tail -f query
That will print the last few lines of the file and if the file changes every new line.
So if you do a SELECT * FROM table you should see the query in the console output.