MySQL Create User Operation failed - mysql

I have been trying to create a MySQL user programmatically.
$this->db->query('CREATE USER 'agit****'#'localhost'); // Using Codeigniter
It returns an error
Operation CREATE USER failed for 'agit****'#'localhost'
I have deleted the user from the mysql.user and tried again.
DROP USER 'agit****'#'localhost';
I have also tried
DROP USER 'agit****'#'%';
and
DELETE FROM `mysql.user` WHERE `user` LIKE 'agit****';
The user got deleted and then I executed the following query:
flush privileges;
and restarted the MySQL server. But no use.
I have tried to create the same user from command line, and it returns the following error code
ERROR 1396 (HY000): Operation CREATE USER failed for
Server details and version numbers
SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 5.5.45 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.45 |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86 |
| version_compile_os | Win64 |
+-------------------------+------------------------------+
7 rows in set (0.00 sec)
Note: This error occurs only when I try to create a user which existed already.
New users can be added without any issue
I have confirmed that the User got deleted from the MySQL.User table before creating the user account again.

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/

permission errors on database for full access user

I am getting an error (on MySQL 5.7.25-google in Google cloud while locally MySQL 5.7.29, it works fine)
Google Cloud, I run (NOTE: show tables shows this table existing from this same user!!!)
mysql> show index from customers;
ERROR 1146 (42S02): Table 'authtables.customers' doesn't exist
and locally (same user and password and setup), I get
mysql> SHOW INDEX FROM customers;
+-----------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| customers | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | | |
Of course, the command SHOW TABLES; works the same on both and shows the CUSTOMERS table in both!!! grrrr.
I followed the accepted answer in the link below EXCEPT for 1 minor detail for setup of 'authservice' user to 'authtables' database...
Mysql adding user for remote access
The ONE detail is my grant statements were authtables.* so that the user had full access to the authtables database and nothing else.
NEXT is my show grants command in GCP and locally which yield the EXACT same result but in case I am missing a typo, here is the GCP then the local result
mysql> show grants for 'authservice'#'localhost';
+---------------------------------------------------------------------+
| Grants for authservice#localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'authservice'#'localhost' |
| GRANT ALL PRIVILEGES ON `authtables`.* TO 'authservice'#'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.08 sec)
local result is
mysql> show grants for 'authservice'#'localhost';
+---------------------------------------------------------------------+
| Grants for authservice#localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'authservice'#'localhost' |
| GRANT ALL PRIVILEGES ON `authtables`.* TO 'authservice'#'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
For completeness...
GCP version: Server version: 5.7.25-google-log (Google)
local version: Server version: 5.7.29 MySQL Community Server (GPL)
WOW, crap, what is 5.7.25-google-log...ICK. I wonder if it has a bug here.
Also, why is grant have . when I look at my history in mysql to verify, I clearly did authtables.* EVERY time!!!
Then, what happened to the 'authservice'#'%' grant as I don't see that either?
Anyone have any idea how to setup google cloud mysql so I have a user with full access to the database so he is restricted to that database? This seems kind of like some sort of google bug or am I doing something wrong?
thanks,
Dean
OMG, google's mysql 'table names' are CASE SENSITIVE!!! what the heck.
I have to do
show index from CUSTOMERS;
OR
SHOW INDEX FROM CUSTOMERS;
BUT THIS DOES NOT WORK
show index from customers;
ouch! posted this to help the next person out hopefully.

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)

Grafana with MySQL: this authentication plugin is not supported

I am trying to load some data from MySQL to Grafana, but got the following error. Any idea what I missed? Thanks!
Its happends couse grafana don't maintain the new mysql authorization method named caching_sha2_password. Sinse mysql 8 its default setting.
To solve this problem you need just to create new user with mysql_native_password authentication plugin connector.
Step 1. Check the available users and its plugins.
MySQL [localhost+ ssl] SQL> select user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| pi | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| root | caching_sha2_password |
+------------------+-----------------------+
6 rows in set (0.0011 sec)
All the users has caching_sha2_password authorization plugin.
Step 2. Open the mysql workbench and connect to database.
Execute the query
CREATE USER 'native_user'#'localhost' IDENTIFIED WITH mysql_native_password;
The result must be like this one
09:30:17 CREATE USER 'native_user'#'localhost' IDENTIFIED WITH mysql_native_password 0 row(s) affected 0.156 sec
Step 3. In mysql workbench open server -> users and privilegas
Select native_user form the list. Change the password, default shema and shema privilegas for this user. Save the changes.
Step 4. Check with mysql shell
MySQL [localhost+ ssl] SQL> select user, plugin from mysql.user ;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| pi | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session | caching_sha2_password |
| mysql.sys | caching_sha2_password |
| native_user | mysql_native_password |
| root | caching_sha2_password |
+------------------+-----------------------+
6 rows in set (0.0011 sec)
Step 5. Open the grafana datasouces and set up new user.
Good luck!
P.S. I cant create a new user with mysql_native_password using mysql workbanch. Maybe its bug. Use command prompt instead.
Thanks. Below works as well. No need to create a new user.
select user,plugin from mysql.user;
alter user root#'localhost' identified with mysql_native_password by 'my_password';
select user,plugin from mysql.user;

Table 'mysql.user' doesn't exist:ERROR

I am creating a db in mysql for a java program.My program works well in my friends system.But I have some problem with my mysql.
The query is below:
mysql> create database sampledb;
Query OK, 1 row affected (0.00 sec)
mysql> use sampledb;
Database changed
mysql> create user zebronics identified by 'zebra123';
ERROR 1146 (42S02): Table 'mysql.user' doesn't exist
I cant create any user for my db.Please help??
My solution was to run
mysql_upgrade -u root
Scenario: I updated the MySQL version on my Mac with 'homebrew upgrade'. Afterwards, some stuff worked, but other commands raised the error described in the question.
Looks like something is messed up with your MySQL installation. The mysql.user table should definitely exist. Try running the command below on your server to create the tables in the database called mysql:
mysql_install_db
If that doesn't work, maybe the permissions on your MySQL data directory are messed up. Look at a "known good" installation as a reference for what the permissions should be.
You could also try re-installing MySQL completely.
Same issue here as lxxxvi describes. Running
mysql_upgrade -u root
allowed me to then successfully enter a password that
mysql_secure_installation
was waiting for.
Your database may be corrupt. Try to check if mysql.user exists:
use mysql;
select * from user;
If these are missing you can try recreating the tables by using
mysql_install_db
or you may have to clean (completely remove it) and reinstall MySQL.
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| datapass_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.05 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables
-> ;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
mysql> create user m identified by 'm';
Query OK, 0 rows affected (0.02 sec)
check for the database mysql and table user as shown above if that dosent work, your mysql installation is not proper.
use the below command as mention in other post to install tables again
mysql_install_db
You can run the following query to check for the existance of the user table.
SELECT * FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '%user%'
See if you can find a row with the following values in
mysql user BASE TABLE MyISAM
If you cant find this table look at the following link to rebuild the database How to recover/recreate mysql's default 'mysql' database
Try run mysqladmin reload, which is located in /usr/loca/mysql/bin/ on mac.
'Error Code: 1046'.
This error shows that the table does not exist may sometimes be caused by having selected a different database and running a query referring to another table. The results indicates
'No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar'.
Will solve the issue and it worked for me very well.
It sometime happens when you run the grant/ privileges query on an empty database