How to GRANT in mysql after REVOKE - mysql

In mysql i executed following command
REVOKE ALL PRIVILEGES
after that i try to give GRANT then it shows Access denied

it would seem that you revoked the GRANT privileges of your own user, you should use the root user to grant those privileges back.
for a review of your status regarding the privileges run from root user:
SHOW GRANTS;

Related

What does each part of this command to grant all privileges mean?

Can someone explain the following command?
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'#'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES
This gives the user specified later in the command all privileges.
http://dev.mysql.com/doc/refman/5.7/en/grant.html
ON *.*
Matches everything.
TO 'user1'#'localhost'
The user with name ‘user1’ on localhost which is to be granted the privileges.
WITH GRANT OPTION
The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.
https://dev.mysql.com/doc/refman/5.6/en/privileges-provided.html#priv_grant-option

MySQL "mysql there is no such grant defined for user"

This error happened when I granted all privileges to a new root account I just created.
Steps to produce the problem:
CREATE USER 'root'#'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SHOW GRANTS for 'root'#'localhost';
After "show grants" I got the error "mysql there is no such grant defined for user 'root' on host 'localhost'". There were no errors after executing the first three commands. The new user was created successfully.
How do I solve this problem?
More info:
I'm running MySQL 5.7 on my MacOS laptop(OSX 10.10.5).
There is nothing wrong with your posted code but as guess try with wildcard symbol % like
SHOW GRANTS for 'root'#'%';
(OR)
As an alternative, login with your created user 'root'#'localhost' and just use SHOW GRANTS. See Documentation
I don't think mysql allows you to create another root account. So the create causes an error.
CREATE USER 'root'#'localhost';
ERROR 1396 (HY000): Operation CREATE USER failed for 'root'#'localhost'
You should check for the existing root account in the user table and you'll find the wildcard to be '%' which should mean you do not need to create a localhost root user.
select * from user where user = 'root';
Asking to show grants on root localhost should work, and does work for me.
show grants for 'root'#'localhost';
Step-1:
sudo mysql -u root -p
Step-2:
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user name'#'localhost';
Ex.-
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'admin'#'localhost';
Step-3:
FLUSH PRIVILEGES;
I think it will work.

Error Code: 1044. Access denied for user

While logging into MySQL using 'root'#10.0.1.15'
I tried to grant a user SELECT, INSERT, UPDATE but got this error from MySQL
Error Code: 1044. Access denied for user 'root'#'10.%' to database 'abc'
This is the query that I used to grant
GRANT SELECT, INSERT, UPDATE ON abc.* TO 'myUser'#'10.%';
This makes no since because when I execute SHOW GRANTS FOR 'root'#'10.%' Here is what I get
GRANT ALL PRIVILEGES ON *.* TO 'root'#'10.%' IDENTIFIED BY PASSWORD 'jklasdfksfkashdfksdfhsdlkfasdfjklasdfsjk'
I tried to do grant all privileges all over again but still getting the same error.
GRANT ALL PRIVILEGES ON *.* TO 'root'#'10.%';
FLUSH PRIVILEGES;
What I could be doing wrong here? why aren't the user 'root'#'10.0.1.15' able to GRANT other users privileges?
Your user needs the GRANT OPTION.
Here's how to change your existing grant to fix that:
GRANT ALL PRIVILEGES ON *.*
TO 'root'#'10.%'
IDENTIFIED BY PASSWORD 'jklasdfksfkashdfksdfhsdlkfasdfjklasdfsjk'
WITH GRANT OPTION

can't login to mysql server after GRANT ALL PRIVILEGES

I had the same problem mentioned here, so I logged in as webuser on mydomain.de/phpmyadmin and executed the query from the most pupolar answer:
GRANT ALL PRIVILEGES ON *.* TO 'webuser'#'localhost' IDENTIFIED BY 'webuser' WITH GRANT OPTION;
After that, I'm not able to login to phpmyadmin anymore with user=webuser.
#1045 Cannot log in to the MySQL server.
But on my website (subdomain.mydomain.de), where I use the same login to connect to my mysql-database, everything is ok.
What have I done and how can I fix this?
Problem solved: I logged in as root and changed the password for webuser.
I think the command GRANT ALL PRIVILEGES ON *.* TO 'webuser'#'localhost' IDENTIFIED BY 'webuser' WITH GRANT OPTION; resettet the password for webuser

Grant privileges to user in MySQL

From the control panel of my website I have created a new MySQL(5) database Test and a new user admin with password 123. I have tried assigning privileges to the user admin using:
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'localhost'
or
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'Test'
I keep getting the following error:
#1045 - Access denied for user 'admin'#'%' (using password: YES)
I need the following privileges for the user admin:
CREATE, ALTER, DELETE, INSERT, SELECT, UPDATE, LOCK TABLES
How do I make that in a query from phpMyAdmin?
I guess you are trying to change privileges of 'admin'#''%' being logged in as that user. This is strange.
You can display which user you are logged in as using
SELECT USER();
Then check grants that account already has:
SHOW GRANTS FOR 'admin'#''%';
We came to the conclusion you have
GRANT ALL PRIVILEGES ON `Test`.* TO 'admin'#'%'
That says you already have all privileges on all tables in database Test. You cannot further grant those privileges to other users, though (otherwise there would be WITH GRANT OPTION).
During the installation of MySQL, root user is always created. Use it to grant privileges to other accounts.
More info in manual:
2.10.2. Securing the Initial MySQL Accounts
6.3.2. Adding User Accounts
After run these statements try to execute FLUSH:
FLUSH PRIVILEGES;
From MYSQL Reference Manual :
(...) If you change the grant tables directly but forget to reload them, your changes have no effect until you restart the server. This may leave you wondering why your changes do not seem to make any difference!
To tell the server to reload the grant tables, perform a flush-privileges operation. (...)
Login as a root user then grant all privileges to admin user.
GRANT ALL PRIVILEGES ON `test`.* TO 'admin'#'localhost';