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
Related
Is it possible to give grant to user by another user? I've created user with full privileges:
CRETAE USER test#localhost IDENTIFIED BY 'test';
GRANT ALL ON *.* TO test#localhost;
GRANT CREATE USER ON *.* TO test#localhost;
FLUSH PRIVILEGES;
But when I tried to give privileges to another user using user 'test' It is written "Access denied to user test#localhost for table 'x'"
Updated: I found the way by edditing Grant_priv mysql.user is there any syntax for that?
The syntax is WITH GRANT OPTION.
CREATE USER test#localhost IDENTIFIED BY 'test';
GRANT ALL ON *.* TO test#localhost WITH GRANT OPTION;
...
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
Oddly enough it seems my mysql will not allow creating a user with access to a specific database. Using MySQL Workbench:
CREATE USER 'testUser'#'localhost' IDENTIFIED BY 'thepasswordhere';
GRANT ALL PRIVILEGES ON testDatabaseName TO 'testUser'#'localhost' WITH GRANT OPTION;
SHOW GRANTS;
I see nothing mentioning granted privileges for the created user. This explains why I get mysqli::mysqli(): (28000/1045): Access denied for user 'testUser'
What step am I missing?? Update: Even when I mistype the username I still get a success with 0 rows affected: GRANT ALL PRIVILEGES ON testDatabaseName TO 'testkUser'#'%' WITH GRANT OPTION; so I think something's seriously wrong with my local mysql. Any ideas on a fix?
CREATE USER 'testUser'#'localhost' IDENTIFIED BY 'thepasswordhere';
GRANT ALL PRIVILEGES ON testDatabaseName.* TO 'testUser'#'localhost' WITH GRANT OPTION;
SELECT sql_grants FROM common_schema.sql_show_grants;
What changed? I simply added a .* after database name. It's necessary so the user has access to all tables inside the database.
Also for the latest mysql, I believe you need to put user password when using grant.
So do as follows:
CREATE USER 'testUser'#'localhost' IDENTIFIED BY 'thepasswordhere';
GRANT ALL PRIVILEGES ON testDatabaseName.* TO testUser#localhost IDENTIFIED BY 'pass' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SELECT sql_grants FROM common_schema.sql_show_grants;
As mentioned by Michael in the question comments:
SHOW GRANTS FOR 'testUser'#'localhost';... otherwise, SHOW GRANTS;
shows your privileges -- the ones associated with the account that is
currently logged in.
I am creating a user app_root identified by a password with limited permission. This user should only be able to create a database with prefix, create a new user, and grant permission to new user to access the database. So this is what I am doing.
CREATE USER app_root#localhost IDENTIFIED BY 'password';
GRANT CREATE USER ON *.* TO app_root#localhost WITH GRANT OPTION;
GRANT CREATE ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
The user is duly created. Now I log in to mysql with app_root user and execute following:
CREATE DATABASE test;
It fails as expected because name of database does not contain myapp_ prefix.
CREATE DATABASE myapp_test;
CREATE USER myapp_test#localhost IDENTIFIED BY 'ABC';
Both database and user are successfully created. But if I execute grant statement, error occurs.
GRANT ALL PRIVILEGES ON myapp_test.* TO myapp_test#localhost;
It generates ERROR 1044 (42000): Access denied for user 'app_root'#'localhost' to database 'myapp_test'. Could anyone please tell me what is wrong with my approach?
MySQL Version - Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)
Edit - As suggested, I granted all privileges to app_root user. But it still does not change anything.
GRANT ALL ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
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;