MySQL/MariaDB drop user with long user name fails - mysql

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)

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 error (42000) Unknown database 'testdb' while trying to connect to mysql remotely from another machine

Dears ,
I have two Virtual machines App1 & db ...
I installed Mysql in db machine , and I am trying on App1 machine to build EAR for springboot-demo-app following steps in this link (https://github.com/Mhussein27/springboot-demo-app)
But I am stuck in the step (mvn package) on app1 machine after exporting Mysql Configuration like the below , I am facing Unknown database error :
export APP_DATABASE_USER=testuser
export APP_DATABASE_PASSWORD=XXX
export APP_DATABASE_URL='jdbc:mysql://db:3306/testdb'
admin#app1:~/springboot-demo-app$ mvn package
Error:
Unable to obtain database connection
------------------------------------
SQL State : 42000
Error Code : 1049
Message : Unknown database 'testdb'
on db machine I can see the testuser and the testdb schema and privileges are fine !
mysql> SELECT User,Host FROM mysql.user;
+---------------+-----------+
| User | Host |
+---------------+-----------+
| testuser | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> SHOW GRANTS FOR 'testuser'#'%';
+------------------------------------------------------+
| Grants for testuser#% |
+------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser'#'%' |
+------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show tables;
+-----------------------+
| Tables_in_testdb |
+-----------------------+
| flyway_schema_history |
+-----------------------+
1 row in set (0.00 sec)
Please let me know what is wrong !!

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...

DROP User 'netbeansuser'#'%'; throws Error HY000 (1396) MySQL

I mistakenly created a user that I now am unable to delete. Following is the code snippet interacting with MySQL:
mysql> DROP User 'netbeansuser'#'%';
ERROR 1396 (HY000): Operation DROP USER failed for 'netbeansuser'#'%'
mysql> select User from mysql.user;
+------------------+
| User |
+------------------+
| root |
| root |
| debian-sys-maint |
| netbeansuser |
| root |
| root |
+------------------+
6 rows in set (0.00 sec)
mysql> DROP User 'netbeansuser';
ERROR 1396 (HY000): Operation DROP USER failed for 'netbeansuser'#'%'
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select User from mysql.user;
+------------------+
| User |
+------------------+
| root |
| root |
| debian-sys-maint |
| netbeansuser |
| root |
| root |
+------------------+
6 rows in set (0.00 sec)
mysql> DROP User 'netbeansuser';
ERROR 1396 (HY000): Operation DROP USER failed for 'netbeansuser'#'%'
mysql> DROP User 'netbeansuser'#'%';
ERROR 1396 (HY000): Operation DROP USER failed for 'netbeansuser'#'%'
What am I doing wrong? Particularly, what is the '%' sign at the hostname for? I didn't specify the hostname while creating the user. Any resources on understanding hostname bindings in MySQL USER creation will also help. Thanks all.
This will be helpful.
Use 'localhost' instead of '%'.

Delete user in MySQL is not working

I am a new to MySQL, and I have created a user called magento as described in the table below. Now I am not able to delete that user!
mysql> SELECT User, Host, Password FROM mysql.user;
+------------------+-------------------+-------------------------------------------+
| User | Host | Password |
+------------------+-------------------+-------------------------------------------+
| root | localhost | *F4F8C81F12A316D6884269A228966F1E5763E16F |
| root | mgaber-virtualbox | *F4F8C81F12A316D6884269A228966F1E5763E16F |
| root | 127.0.0.1 | *F4F8C81F12A316D6884269A228966F1E5763E16F |
| root | ::1 | *F4F8C81F12A316D6884269A228966F1E5763E16F |
| debian-sys-maint | localhost | *63EDFEF710866BF1C20505D01DCEFBAA246750BC |
| ‘magento’ | ’localhost’ | |
+------------------+-------------------+-------------------------------------------+
I have used the below commands.
mysql> drop user ‘magento’;
ERROR 1396 (HY000): Operation DROP USER failed for '‘magento’'#'%'
mysql> drop user ‘magento’#'localhost';
ERROR 1396 (HY000): Operation DROP USER failed for '‘magento’'#'localhost'
Both are not working.
How can I fix this problem?
Change this
mysql> drop user ‘magento’;
to
drop user 'magento'#'localhost';
You have to use the right quotes ' and not ‘.
Or use this:
DELETE FROM users where user = 'magento'
check this