Unable to LOAD_FILE in Maria DB - mariadb

I am using Maria DB on Ubuntu 1804 :
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
I want to do something relatively easy and I have wasted 2 hours on it. I want to load a file as a string. There are several questions (many of them really old) on this site but none of them lead me to a solution and I have tested everything til reaching total frustration.
Granting privileges :
MariaDB [(none)]> GRANT FILE ON *.* TO matias#localhost;;
Query OK, 0 rows affected (0.00 sec)
ERROR: No query specified
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SHOW GRANTS FOR matias#localhost
-> ;
+------------------------------------------------------------------------------------------------------------------------+
| Grants for matias#localhost |
+------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'matias'#'localhost' IDENTIFIED BY PASSWORD '*???' |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
No secure_file_priv :
MariaDB [(none)]> SHOW VARIABLES LIKE 'secure_file_priv';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
+------------------+-------+
1 row in set (0.00 sec)
Right permissions on the file :
[~]#Ubuntu1804 #> ls -lh test.txt
-rw-rw-r-- 1 matias matias 6 Feb 29 23:44 test.txt
And still cant get the file :
MariaDB [(none)]> SELECT USER();
+------------------+
| USER() |
+------------------+
| matias#localhost |
+------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> SELECT LOAD_FILE('/home/matias/test.txt');
+------------------------------------+
| LOAD_FILE('/home/matias/test.txt') |
+------------------------------------+
| NULL |
+------------------------------------+
1 row in set (0.00 sec)
Can someone point me on the right direction to solve this?

Well, I tried EVERYTHING under the sun and it never worked.
So I tried with Ubuntu 19.10 instead of 18.04 and it works like charm,
so unless someone has some magic card on his sleeve this is the only workaround I could come up with.
All in all, it works in Ubuntu 16.04 and 19.10.

Related

How to modify MariaDB SQL Error Log plugin system variables?

I just installed this plugin to monitor SQL errors:
https://mariadb.com/kb/en/sql-error-log-plugin/
but I can't for the life of me find anything on how to modify the default system variables for that error log plugin, and where.
Anyone?!
You can't modify error plugin log variables via SQL statements. They are either read-only and/or they need to be specified at startup (see source code).
So you have to pass these values either to mariadbd/mysqld or you have to specify these in your configuration file.
Example in /etc/my.cnf:
[server]
sql-error-log-filename=foo.log
sql-error-log-rotate=ON
restart server and check the values
MariaDB [test]> show variables like 'sql_error%';
+--------------------------+---------+
| Variable_name | Value |
+--------------------------+---------+
| sql_error_log_filename | foo.log |
| sql_error_log_rate | 1 |
| sql_error_log_rotate | ON |
| sql_error_log_rotations | 9 |
| sql_error_log_size_limit | 1000000 |
+--------------------------+---------+

Disable strict mode on MariaDB

When i run this sql in phpmyadmin
SELECT ##SQL_MODE, ##GLOBAL.SQL_MODE;
it shows
##SQL_MODE STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
##GLOBAL.SQL_MODE STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
How to Disable strict mode on MariaDB using phpmydmin?
Edit via SSH
/etc/my.cnf file
Add
sql_mode=NO_ENGINE_SUBSTITUTION
restart MariaDB
and it will fix the issue
*edit - if You have error while restarting msyql service try to add "[mysqld]" above in my.cnf
This worked for me:
root#MaRs:/etc/mysql# cat my.cnf|grep -v \#
[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
root#MaRs:/etc/mysql#
MariaDB [(none)]> SELECT ##SQL_MODE, ##GLOBAL.SQL_MODE;
+------------------------+------------------------+
| ##SQL_MODE | ##GLOBAL.SQL_MODE |
+------------------------+------------------------+
| NO_ENGINE_SUBSTITUTION | NO_ENGINE_SUBSTITUTION |
+------------------------+------------------------+
1 row in set (0.000 sec)

mariadb server: I can't stop the server with `mysql.server stop`

OSX 10.13.6
I installed mariadb sever with homebrew a few years ago, and I use it infrequently. Today, I tried to start mariadb using the command:
$ mysql.server start
and I got a bunch of errors. So, I did:
$ brew update
then:
$ brew uprade mariadb
That completed fine, and now I can start mariadb with:
$ mysql.server start
and I can access all my old db's.
The problem I'm having is that I cannot stop mysql. Both these commands hang:
$ mysql.server stop
and(in another terminal window):
$ mysql.server status
According to the MariaDB docs for mysql.server, both those commands should work.
Currently, I'm killing the server like this:
$ killall mysqld mysqld_safe
then checking that the server was killed with this:
$ ps aux | grep mysqld
When I run the ps command when mysql is running, I get:
~$ ps aux | grep mysqld
7stud 3707 0.0 1.0 4808208 79948 s005 S 1:26PM 0:00.47
/usr/local/Cellar/mariadb/10.3.15/bin/mysqld
--basedir=/usr/local/Cellar/mariadb/10.3.15 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mariadb/10.3.15/lib/plugin --log-error=/usr/local/var/mysql/My-MacBook-Pro-2.local.err --pid-file=/usr/local/var/mysql/My-MacBook-Pro-2.local.pid
7stud 3643 0.0 0.0 4287792 1460 s005 S 1:26PM 0:00.02 /bin/sh
/usr/local/Cellar/mariadb/10.3.15/bin/mysqld_safe
--datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/My-MacBook-Pro-2.local.pid
7stud 4544 0.0 0.0 4267752 880 s000 S+ 1:41PM 0:00.00
grep mysqld
What is the proper way to shut down the mariadb server?
mysql> SHOW VARIABLES LIKE '%vers%';
+---------------------------------+------------------------------------------+
| Variable_name | Value |
+---------------------------------+------------------------------------------+
| innodb_version | 10.3.15 |
| protocol_version | 10 |
| slave_type_conversions | |
| system_versioning_alter_history | ERROR |
| system_versioning_asof | DEFAULT |
| thread_pool_oversubscribe | 3 |
| version | 10.3.15-MariaDB |
| version_comment | Homebrew |
| version_compile_machine | x86_64 |
| version_compile_os | osx10.13 |
| version_malloc_library | system |
| version_source_revision | 07aef9f7eb936de2b277f8ae209a1fd72510c011 |
| version_ssl_library | OpenSSL 1.0.2r 26 Feb 2019 |
| wsrep_patch_version | wsrep_25.24 |
+---------------------------------+------------------------------------------+
14 rows in set (0.01 sec)
I had the same issue, tried to use mysql.server stop and mysql.server status after running mysql.server start but they will just run indefinitely.
If you are using a Mac seems that mysql.server stop won't work... I installed mariadb with homebrew and found out that I can use brew services to start and stop it in this link:
https://dba.stackexchange.com/questions/214883/homebrew-mariadb-server-start-error-with-mysql-server-start
The commands are pretty simple and they work for me
brew services start mariadb
brew services stop mariadb
It may be a little late but I hope this helps you to figure out your problem.
See https://stackoverflow.com/a/59938033/4579271 for details.
To fix, run:
cp /usr/local/bin/mysql.server /usr/local/bin/mysql.server.backup
sed -i "" "s/user='mysql'/user=\`whoami\`/g" /usr/local/bin/mysql.server

Wordpress and phpMyAdmin cannot open a RDS database

I created a WordPress multisite on an EC2 using CentOS 7 with MariaDB.
Amazingly it works.
I followed the instructions here
to upload the database
using MySQL from a command line I can attach to and see the RDS database.
MariaDB [(none)]> SHOW databases;
+--------------------+
| Database |
+--------------------+
| WPDB01 |
| information_schema |
| innodb |
| mysql |
| performance_schema |
+--------------------+
MariaDB [(none)]> select User, Host from mysql.user;
+-----------------+-----------+
| User | Host |
+-----------------+-----------+
| WordPressAbuser | % |
| WordPressUser | % |
| rdsadmin | localhost |
+-----------------+-----------+
So I know the ports are open and the database is there.
But changing localhost inside of wp-config.php to mymariadb.xyz.us-east-1.rds.amazonaws.com does not work.
What am I doing wrong?
Check if Your EC2 security group is attached to RDS security group?
check the below image of rds security group
Your RDS should have a new separate security group and in the source, you have to add ec2 security group.
that rds security group should be attached to you rds instance
the ec2 security group should attach to the corresponding ec2 instance
then try to connect

InnoDB tables exist in MySQL but says they do not exist after copying database to new server

I used mysqldump to export my database and then I imported it into MySQL on my other server. I can now see all my tables if I do "show tables" but I can't actually select from or describe any of them.
ERROR 1146 (42S02): Table 'mydatabase.user' doesn't exist
All of my tables are InnoDB. I saw one issue people had where they were using old_passwords, so I explicitly set that to 0 in my.cnf and I made sure all of the passwords in the mysql table were 41 hexadecimal digits as they should be for the new passwords.
The reason "show tables;" works is because mysqld will scan the database directory for .frm files only. As long as they exist, it sees a table definition.
If you imported the data into MySQL and this error message happens, the first thing I would immediately do is run this command: (BTW This is MySQL 5.1.45, but works in MySQL 5.x anyway)
mysql> show engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.00 sec)
If the server you imported the data into says InnoDB is disabled, then you have a big problem. Here is what you should do:
1) Drop all the Data from the New Import DB Server
2) Cleanup InnoDB Setup
3) run SHOW ENGINES; and make sure InnoDB is fully operational !!!
4) Reload the mysqldump into the new import server
Give it a Try !!!
I had this problem when I changed from a windows server to a Linux server.
Tables are files, and windows files are case insesitive, but linux files are case sensitive.
In my aplication, in the sql queries, some times I used uppercase tablenames and other times lowercase, so, sometimes I obtained the same result as you.
I my case it was SQLCA.DBParm parameter.
I used SQLCA.DBParm = "Databse = "sle_database.text"" but it must be
SQLCA.DBParm = "Database='" +sle_database.text+ "'"
Explain : you are going to combine three strings :
a) Database=' - "Database='"
b) (name of the database) - +sle_database.text+
c) ' - "'"

Resources