Can't get load_file() working in mysql - mysql

I've been struggling for 2 nights now to get load_file() to work, but the results are NULL.
I run version "5.6.19-0ubuntu0.14.04.1".
Example:
mysql> show variables like '%secure%';
+------------------+-------------+
| Variable_name | Value |
+------------------+-------------+
| secure_auth | ON |
| secure_file_priv | /root/load/ |
+------------------+-------------+
mysql> show variables like 'max_allowed%';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
mysql> desc xmlDocs;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| fileName | varchar(30) | NO | PRI | NULL | |
| server | varchar(20) | NO | | NULL | |
| doc_content | blob | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
mysql> insert into xmlDocs values ('test','test',load_file('/root/load/test.xml'));
ERROR 1048 (23000): Column 'doc_content' cannot be null
File permissions:
drwxrwxr-x 5 mysql mysql 4096 Nov 24 08:18 .
drwx------ 6 root root 4096 Nov 24 08:33 ..
drwxr--r-- 5 root root 4096 Nov 22 16:24 EU1
drwxr--r-- 5 root root 4096 Nov 22 16:26 server
-rwxrwxrwx 1 mysql mysql 83440 Nov 24 08:18 test.xml
drwxr--r-- 5 root root 4096 Nov 22 16:24 US1
Checked:
MySql has execute and even owns the dir
Mysql ows the file
DB user = root
Filesize < max_allowed_packets
secure-file-priv is set
I have no apparmor running
Without setting secure-file-priv it can read non important data like /etc/passwd effortlessly :P. Also from "/" i can import, but nowhere else.
When setting secure-file-priv, I can get it to work from "/" only!
Same file, no secure-file-priv set:
mysql> insert into xmlDocs values ('test','test',load_file("/root/load/test.xml"));
ERROR 1048 (23000): Column 'doc_content' cannot be null
mysql> insert into xmlDocs values ('test','test',load_file("/etc/test.xml"));
Query OK, 1 row affected (0.00 sec)
Any ideas?

Typical ... been looking for 2 days and 5 minutes after posting it here i figured it out.
The file to be loaded, not just the folder it's located in must have execute ... EVERY folder in it's path up to "/" must have execute!

Related

Access denied to remote user when doing LOCK TABLES

I'm running mariadb-server v10.2.33-1 on two openwrt-qemu systems. I want a remote user to achieve LOCK TABLE on a particular table.
In the local mysql server, I have created a remote user and granted LOCK TABLES privilege using the following commands:
CREATE USER 'root'#'192.168.%' IDENTIFIED BY 'root';
GRANT SELECT ON `qkd`.`RawKeyStatus` TO 'root'#'192.168.%';
GRANT LOCK TABLES ON `qkd`.* TO 'root'#'192.168.%';
FLUSH PRIVILEGES;
Upon running SHOW GRANTS in the remote user system, I can notice the LOCK TABLES privilege has been assigned to 'root'#'192.168.%'. The remote user also has SELECT privilege on the table qkd.RawKeyStatus.
However LOCK TABLE qkd.RawKeyStatus READ; command in the remote system fails with the error:
ERROR 1044 (42000): Access denied for user 'root'#'192.168.%' to database 'qkd'
What am I missing ?
Run SHOW PROCESSLIST; nd see from which System the remote user is login and change the GRANT if it not 192.168,%
MariaDB [(none)]> show processlist;
+------+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+------+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 3357 | root | localhost | NULL | Query | 0 | init | show processlist | 0.000 |
+------+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
6 rows in set (0.01 sec)
MariaDB [(none)]>
UPDATE:
The issue was related to the wildcard 192.168.%. In order to give GRANT to all users of the subnet 192.168.A.B a correct wildcard would be 192.168.%.%
A more safer option is to use a subnet mask:
GRANT ... TO 'user'#'192.168.0.0/255.255.255.0' IDENTIFIED BY ...
Now LOCK TABLE qkd.RawKeyStatus READ; command runs perfectly with the output
Query OK, 0 rows affected (0.02 sec)
Reference: How to grant remote access to MySQL for a whole subnet?
A quick workaround is to pass the –-single-transaction option to mysqldump:
for example:
$ mysqldump --single-transaction -u user -p DBNAME > backup.sql
ref: https://michaelrigart.be/mysqldump-1044-access-denied-using-lock-tables/

MySQL/MariaDB drop user with long user name fails

I'm running MySQL Ver 15.1 Distrib 10.3.9-MariaDB for OSX10.13 and have a bunch of users (around 14) where the username is apparently too long, see below.
MariaDB [(none)]> SELECT Host, User FROM mysql.user;
+-----------+-------------------------+
| Host | User |
+-----------+-------------------------+
| 127.0.0.1 | tenant_2SxSBywyXh3QW5L4 |
| 127.0.0.1 | tenant_4j3CWVXjgtDD2OrI |
| 127.0.0.1 | tenant_5OOBxRgjSvFehwI2 |
| 127.0.0.1 | tenant_6C3vAqBTVns8rMTT |
| 127.0.0.1 | tenant_9PVCY1Msa61u43Oh |
| 127.0.0.1 | tenant_RyFspluIGEi3Fkby |
| 127.0.0.1 | tenant_SQtfEQZmWRFfKmHy |
| 127.0.0.1 | tenant_VC8pYaJ3it1LdYK3 |
| 127.0.0.1 | tenant_Zr84h3vkLdwkqR33 |
| 127.0.0.1 | tenant_cvifD1I2Rjghjnpu |
| 127.0.0.1 | tenant_jO1tUJJokremTW5P |
| 127.0.0.1 | tenant_p6Bhzhi0OqMH4gc9 |
| 127.0.0.1 | tenant_rjyOX1NqEN6k6mk4 |
| 127.0.0.1 | tenant_xfcHjsn0mHBfURAw |
| 127.0.0.1 | test_testing_local |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+-------------------------+
18 rows in set (0.000 sec)
When I try to drop these users using the following command I'm in encountering this error:
MariaDB [(none)]> DROP USER 'tenant_5OOBxRgjSvFehwI2#127.0.0.1';
ERROR 1470 (HY000): String 'tenant_5OOBxRgjSvFehwI2#127.0.0.1' is too long for user name (should be no longer than 32)
MariaDB [(none)]> DROP USER 'tenant_5OOBxRgjSvFehwI2#localhost';
ERROR 1470 (HY000): String 'tenant_5OOBxRgjSvFehwI2#localhost' is too long for user name (should be no longer than 32)
Any idea's on how I can drop these users?
Most annoying side effect of this is when opening up SequalPro, and I get 14 errors (one after the other) notifying me of this user name being too long issue.
Also, another odd question that I'd be interested to hear about is why when these user name are only 22-24 characters long are they causing a ... too long for user name (should be no longer than 32) error, as they don't breach the 32 character limit?
Appreciate any help :)
You can try several options. Can try the latest test build of SequelPro. The test build (3477d22) seems to solve the long names issue for me.
Test Builds are here: https://sequelpro.com/test-builds
Or one of the latest development builds. http://nightly.sequelpro.com/
For me, with Mariadb 10.x server and nightly build, it also worked for me.
You have to comment the 'username' # 'host' ...
Use:
DROP USER 'tenant_5OOBxRgjSvFehwI2'#'127.0.0.1';
I can't reproduce the problem:
MariaDB [(none)]> SELECT VERSION();
+-----------------+
| VERSION() |
+-----------------+
| 10.3.11-MariaDB |
+-----------------+
1 row in set (0.000 sec)
MariaDB [(none)]> DESC mysql.user; -- User char(80)
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(80) | NO | PRI | | |
.
.
.
+------------------------+-----------------------------------+------+-----+----------+-------+
47 rows in set (0.001 sec)
MariaDB [(none)]> CREATE USER 'tenant_5OOBxRgjSvFehwI2'#'127.0.0.1';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> DROP USER 'tenant_5OOBxRgjSvFehwI2#127.0.0.1';
ERROR 1396 (HY000): Operation DROP USER failed for 'tenant_5OOBxRgjSvFehwI2#127.0.0.1'#'%'
MariaDB [(none)]> DROP USER 'tenant_5OOBxRgjSvFehwI2I'#'127.0.0.1'; -- Wrong user
ERROR 1396 (HY000): Operation DROP USER failed for 'tenant_5OOBxRgjSvFehwI2I'#'127.0.0.1'
MariaDB [(none)]> DROP USER 'tenant_5OOBxRgjSvFehwI2'#'127.0.0.1';
Query OK, 0 rows affected (0.001 sec)

PhpStorm MySQL connection timeout

I use PhpStorm 2016.3.2 and I want to connect my MySQL database.
But, when I want to connect, I have a timeout exception.
I checked the connection hots/port :
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
mysql> show processlist;
+-----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+------+---------+------+----------+------------------+
| 287 | root | localhost | NULL | Query | 0 | starting | show processlist |
+-----+------+-----------+------+---------+------+----------+------------------+
1 row in set (0,00 sec)
mysql>
I have download jdbc connector/j here and copy/past the mysql-connector-java-5.1.40-bin.jar file in /Library/Java/Extensions. I have add this file to my PhpStorm MySQL Driver :
My Database connection config :
I do not understand why he can not connect...

MySQL tee (\T) command doesn't output my queries or my comments

GOAL: to output all SQL queries and their outputs into a text file
SQL CODE:
\W /*enable warnings*/
USE bookdb; /*doesn't exist because I WILL DROP DATABASE booksdb BEFORE RUNNING THIS SCRIPT (to avoid duplicate entry errors from testing out the queries during the assignment)*/
/* Query 0 */
SELECT user(), current_date(), version(), ##sql_mode\G
/*Query 1*/
CREATE DATABASE IF NOT EXISTS bookdb;
Use bookdb;
/*QUERY 2*/
CREATE TABLE books (
isbn CHAR(10),
author VARCHAR(100) NOT NULL,
title VARCHAR(128) NOT NULL,
price DECIMAL(7 , 2 ) NOT NULL,
subject VARCHAR(30) NOT NULL,
PRIMARY KEY (isbn)
)ENGINE = INNODB;
/*QUERY 3*/
INSERT INTO books
VALUES ('0345377648', 'Anne Rice', 'Lasher', 14.00, 'FICTION');
INSERT INTO books
VALUES ('1557044287','Ridley Scott','Gladiator',26.36,'FICTION');
INSERT INTO books
VALUES ('0684856093', 'Sean Covey', 'The 7 Habits', 12, 'CHILDREN');
/*QUERY 4*/
SHOW TABLES;
/*QUERY 5*/
DESC books;
/*QUERY 6*/
SELECT * FROM books;
/*QUERY 7*/
SELECT ISBN, title, price FROM books;
COMMANDS FROM SQL PROMPT:
mysql> tee /my_scripts/yourname_assignment1.txt
mysql> source /my_scripts/yourname_assignment1.sql
mysql> notee
RESULTING assignment1.txt FILE:
user(): root#localhost
current_date(): 2016-09-25
version(): 5.7.15-0ubuntu0.16.04.1
##sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_ FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
1 row in set (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.32 sec)
Query OK, 1 row affected (0.06 sec)
Query OK, 1 row affected (0.04 sec)
Query OK, 1 row affected (0.08 sec)
+------------------+
| Tables_in_bookdb |
+------------------+
| books |
+------------------+
1 row in set (0.00 sec)
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| isbn | char(10) | NO | PRI | NULL | |
| author | varchar(100) | NO | | NULL | |
| title | varchar(128) | NO | | NULL | |
| price | decimal(7,2) | NO | | NULL | |
| subject | varchar(30) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
+------------+--------------+--------------+-------+----------+
| isbn | author | title | price | subject |
+------------+--------------+--------------+-------+----------+
| 0345377648 | Anne Rice | Lasher | 14.00 | FICTION |
| 0684856093 | Sean Covey | The 7 Habits | 12.00 | CHILDREN |
| 1557044287 | Ridley Scott | Gladiator | 26.36 | FICTION |
+------------+--------------+--------------+-------+----------+
3 rows in set (0.00 sec)
+------------+--------------+-------+
| ISBN | title | price |
+------------+--------------+-------+
| 0345377648 | Lasher | 14.00 |
| 0684856093 | The 7 Habits | 12.00 |
| 1557044287 | Gladiator | 26.36 |
+------------+--------------+-------+
3 rows in set (0.00 sec)
mysql> notee
As you can see, my queries are executed without errors (ie. they are coming out correctly), but the output is not listing the queries themselves.
My professor's "example.txt" file includes the queries that are listed in the assignment1.sql file. In other words, his output apparently includes his queries in the SQL file where my output does not. How do you change the "tee" command to include the queries? Did my professor simply manually edit a copy of the file or am I missing something?
I realize that if I manually enter the commands, my output will look more like his (ie. with the queries), but that's not the way he explained this assignment.
I'm running the latest x64 Ubuntu OS if that might have an effect on the SQL. I'm new to this. I've thoroughly searched online for this specific issue, but no one has this one listed.
Thank you.
ASSIGNMENT DIRECTIONS IF THIS CLARIFIES ANYTHING:
Run the following command:
mysql -u root –p --force --comments –vvv
Use the tee command to put your output in a text file to submit.
mysql> tee c:/my_scripts/yourname_assignment1.txt
Run the SQL script hibrahim_assignment1.sql
mysql> source c:\my_scripts\yourname_assignment1.sql
Type in notee to stop the tee command.
mysql> notee
I fixed it. It was because my Linux machine was not giving permissions correctly. The command
mysql -u root -p --force --comments -vvv
required elevation (and didn't require root). I guess I was missing the --force --comments -vvv hence the queries and comments not being included. So for future reference, you'll need elevation. Furthermore, I didn't need to specify root. So the resulting command is
sudo mysql --force --comments -vvv

phpmyAdmin gives error while database and tables look good in mySQL CLI

I changed a name of the table from within phpMyAdmin, and immediately it crapped. after that when I try to connect using phpMyAdmin (/phpMyAdmin/index.php) I get error in log:
[Wed Aug 08 14:18:58 2012] [error] Query call failed: Table 'mydb.mychangedtbl' doesn't exist (1146)
mychangedtbl is the table whose name was changed. this issue is only in phpMyAdmin, I am able to access the database and tables find from CLI. I restarted mySQL, but that did not fix. Seems like something is stuck for phpMyAdmin. I restarted browser also but that didnt help either.
when i rename this particular table back to what it was using command line, myphphAmin works fine again. here is the structure of this table:
mysql> DESCRIBE mychangedtbl;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| userid | char(6) | NO | PRI | NULL | |
| userpass | varchar(40) | NO | | NULL | |
| userlevel | char(3) | NO | | o | |
| userpcip | varchar(45) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql>
column userpass has Collation = asci_bin which it does not show in above output, other columns are ascii_general_ci
pl advice.
ty.
Rajeev
this was due to the reason that, apache was using the same table to do mysql authentication. i changed apache config and restart. that let me change table name. all good again.