Privileges for CREATE table on MySQL, given all privileges - mysql

This is the user privileges:
GRANT USAGE ON *.* TO 'LMMXT'#'localhost' IDENTIFIED BY PASSWORD '*...'
GRANT ALL PRIVILEGES ON `LMMXT`.`*` TO 'LMMXT'#'localhost'
I can LOGIN with the user, USE Database, but always when I want CREATE TABLE:
# mysql -u LMMXT -p -h localhost
mysql> use LMMXT
Database changed
mysql> create table test;
ERROR 1142 (42000): CREATE command denied to user 'LMMXT'#'localhost' for table 'test'
And:
mysql> SELECT USER(),CURRENT_USER();
+---------------------+---------------------+
| USER() | CURRENT_USER() |
+---------------------+---------------------+
| LMMXT#localhost | LMMXT#localhost |
+---------------------+---------------------+
1 row in set (0.00 sec)
So, also I've tried with:
mysql> FLUSH PRIVILEGES;
User is set for host access from 'localhost' and '%'
I've seen other solutions on StackOverflow, but none works.
Thanks in advance

Try changing your grant statement to
GRANT ALL PRIVILEGES ON LMMXT.* TO 'LMMXT'#'localhost'
I'm not sure if the ` characters around the statement are causing a problem

Related

MySQL create table issue with --read-only error

I'd like to create a user who has all privileges with his own database in MySQL.
When I use this user to create a table, MySQL returns that the SQL server is running with read-only option.
However when I changed to an another existing user with all privileges on *.*, I can create table without error.
I'm wondering if the read-only option is global or what?
The following is my MySQL commands using MySQL root:
mysql> create user 'demo'#'localhost' identified by 'demo';
mysql> create database demo;
mysql> grant all privileges on demo.* to demo#localhost;
mysql> show grants for demo#localhost;
+-------------------------------------------------------------------------------------------------------------------+
| Grants for demo#localhost |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'demo'#'localhost' IDENTIFIED BY PASSWORD '*demo-hashed*' |
| GRANT ALL PRIVILEGES ON `demo`.* TO 'demo'#'localhost' |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Then I switched to user "demo":
mysql> use demo;
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> create table t(t1 int);
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement
So I checked the read-only option, and it seems to be on.
However then I tried using another user with privileges on *.* and I can create tables successfully.
The another user grant setting:
mysql> show grants for demo2#'%';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for demo2#% |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'demo2'#'%' IDENTIFIED BY PASSWORD '*demo2-hased*' |
+-----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MySQL version:
mysql> select version();
+------------------------+
| version() |
+------------------------+
| 5.1.68.0 |
+------------------------+
1 row in set (0.00 sec)
BTW, after I set read_only = 0 I can use demo to create table. I just don't know why the demo2 can create table while read-only is on.
Thanks!
Please check the My.cnf for Linux or My.ini for windows under [mysqld] remove read only parameters then restart the service and try again that will solve the read only problem, but if you create table in read only that will be a temp table.

how to import mysql database in wavemaker

While importing I am getting an error
Connection failed: SQLException: Access denied for user 'root'#'localhost' (using password: YES)
What could be the possible solution for this?
Here are my notes on the subject. I had the same issue and saved these notes for future use. There are two methods that I know of for creating users and setting permissions-- I hope they are helpful.
mysql> select password('12345');
+-------------------------+
| password('123456') |
+-------------------------+
| 2ff898e158cd0311 |
+-------------------------+
1 row in set (0.00 sec)
mysql> create user test identified by password '2ff898e158cd0311';
A) Expects #password to be a hash string 1 value:
GRANT ALL PRIVILEGES
ON `mydb` . * TO 'username'#'localhost' IDENTIFIED
BY
PASSWORD '#password';
Note the use of the PASSWORD keyword!
B) Expects #password to be a clear-text string value:
GRANT ALL PRIVILEGES
ON `mydb` . * TO 'username'#'localhost' IDENTIFIED
BY '#password';

ERROR 1396 (HY000): Operation DROP USER failed for 'user'#'localhost'

I have created a user in mysql. Now i want to delete the user ? How to do that? I am getting this error :
ERROR 1396 (HY000): Operation DROP USER failed for 'user'#'localhost'
I am using this command :
DROP USER 'user'#'localhost';
Its an amazon machine.
Thanks
It was because i created the user using command :
CREATE USER 'user'#'%' IDENTIFIED BY 'passwd';
and i was deleting it using :
drop user 'user'#'localhost';
and i should have used this command :
drop user 'user'#'%';
It is likely that the user you are trying to drop does not exist. You can confirm (or not) whether this is the case by running:
select user,host
from mysql.user
where user = '<your-user>';
If the user does exist then try running:
flush privileges;
drop user 'user'#'localhost';
Another thing to check is to make sure you are logged in as root user
If all else fails then you can manually remove the user like this:
delete from mysql.user
where user='<your-user>'
and host = 'localhost';
flush privileges;
How to solve problem like this:
mysql> drop user 'q10'#'localhost';
ERROR 1396 (HY000): Operation DROP USER failed for 'q10'#'localhost'
First:you should check what host of your user,such as:
mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| % | q10 |
| localhost | root |
| localhost | sy |
| localhost | tom |
+-----------+------+
if I drop user 'q10',the command is :
mysql> drop user 'q10'#'%';
Query OK, 0 rows affected (0.00 sec)
And if I drop user 'tom',the command as follow:
mysql> drop user 'tom'#'localhost';
Query OK, 0 rows affected (0.00 sec)
Try using 'user'#'localhost' without quotes:
DROP USER user#localhost;
It should work that way in MySQL 8. I also had that problem.
delete from mysql.user where user='user_name' and host = 'localhost';
flush privileges;
Working for me...

After enable remote access, ROOT lost privileges and grant privilege to ROOT doesn't work

AFTER update user set host='%' where user='root, I lost some of the privileges from my MySQL root user. So I stopped the server and started it with --skip-grant-tables
msqld --skip-grant-tables
and I tried
mysql>update mysql.user set grant_priv = 'Y' where user = 'root';
Query OK, 0 rows affected (0.00 sec)
mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
This doesn't work for me. When I log in as root, I still can't see the MYSQL database.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
Please help. I've tried all the solutions still can't restore the privileges for ROOT, always got the "0 row affected" result.
Try
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Update
Run this command to check your current privileges
SHOW GRANTS FOR CURRENT_USER;
It is a bad practice to insert/update/delete from mysql.* tables and information_schema.* tables using direct SQL DML statements.
Update 2
Can you post the results of this command
SELECT (
Host,
Grant_priv,
Super_priv
)
FROM mysql.user
WHERE user = 'root';
All of the _priv columns should have a value Y. And the Host should be localhost.

Creating a user without deleting, updating and altering privileges in MySQL

I have to provide direct access to my database to some users for auditing purposes, and should add a restriction to avoid that these new users don't have deleting, updating and altering privileges.
Just create a user and grant only SELECT privilege.
CREATE USER user_name#host_name identified by 'password';
GRANT SELECT ON db_name.* TO user_name#host_name;
To check what privileges a user has use
SHOW GRANTS FOR user_name#host_name;
and make sure that a user only has GRANT USAGE and GRANT SELECT ON db_name.*
Lets say I have my_db database with test table in it and I want to create a user with a name user1 who will be allowed to connect only from local host and will be able to read data from all tables in this database but won't be able to insert, change, and delete data.
mysql> create user user1#localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for user1#localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for user1#localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user1'#'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> grant select on my_db.* to user1#localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for user1#localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for user1#localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user1'#'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT SELECT ON `my_db`.* TO 'user1'#'localhost' |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Now lets see what our user1 can and can't do
$ mysql -uuser1 -p
mysql> use mysql
ERROR 1044 (42000): Access denied for user 'user1'#'localhost' to database 'mysql'
mysql> use test
ERROR 1044 (42000): Access denied for user 'user1'#'localhost' to database 'test'
mysql> use my_db
Database changed
As you can see our user1 can only connect to my_db database.
Now let see what that user can do with data in table test (the only table in that database)
mysql> select * from test;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
mysql> insert into test values (3);
ERROR 1142 (42000): INSERT command denied to user 'user1'#'localhost' for table 'test'
mysql> delete from test where id = 1;
ERROR 1142 (42000): DELETE command denied to user 'user1'#'localhost' for table 'test'
mysql> update test set id = 10 where id = 1;
ERROR 1142 (42000): UPDATE command denied to user 'user1'#'localhost' for table 'test'
Again as you can the user can only select from the table.