my sql access denied in spite of granting privileges - mysql

I wanted to execute instructions to create and manipulate a data base so first I created a user as follow:
shell>cd program\xampp\mysql\bin;
shell>mysql -u root -h localhost
mariadb[(none)]>create user 'iw3htp#localhost'identified by 'sth';
grant all privileges on *.* to 'iw3htp#localhost';
flush privileges;
but when I want to execute instructions for creating and manipulating a database using source file or manually i face with error 1044 that says me "Access denied for user 'iw3htp'#'localhost'for database foo.
so whats wrong with this?
what I have to do?

A user access is defined by the user name and the host. Two parts.
With this:
create user 'iw3htp#localhost' ...
as a single string you have created a user
'iw3htp#localhost'#localhost
Change it to
create user 'iw3htp'#'localhost' identified by 'sth';
and
grant all privileges on *.* to 'iw3htp'#'localhost';

Related

Unable to change grant privileges for another user from root user

I'm logged in as root user to an Amazon RDS MySql 5.7 database from MySql workbench.
I've added a user via the following command:
CREATE USER 'my_user'#'%' IDENTIFIED BY 'mypassword';
I'm trying to grant access to the user via this command:
GRANT ALL ON *.* TO 'my_user'#'%'
However, this returns the error:
Error Code: 1045. Access denied for user 'root'#'%' (using password: YES)
I'm not sure if this should work if the user already exists, so based in this post:
https://serverfault.com/questions/115950/how-do-i-change-the-privileges-for-mysql-user-that-is-already-created
I also tried this command:
revoke all privileges on *.* from 'my_user'#'%'
However, I receive the same result. I also had the same problem when I tried creating the user with the GRANT command.
Any help appreciated.
This isn't an answer, but I think the root user might be restricted on RDS. When I did a native install of mysql, the command worked.
None other than RDS user can't have the root user privileges.

mysql: database specific user permission delegation with grant option and wildcard

I want to have a non-root mysql user that can create another databases and users and grant access to that users to created databases. To do this as root I firstly created a user
CREATE USER asusi_admin#localhost IDENTIFIED BY '123';
Then I grant create user PRIVILEGE to this user
GRANT CREATE USER ON *.* TO 'asusi_admin'#localhost';
Then I grant all privileges to this user for the every database he creates
GRANT ALL PRIVILEGES ON `asusi\_%`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
Now I'm flushing privileges
FLUSH PRIVILEGES;
Now I'm logging on to MySQL as newly created user asusi_admin and creating a new database
Now I'm creating a new database
CREATE DATABASE asusi_database;
Now I'm checking that I can use this database
USE asusi_database;
I can use this database, good
Now I'm creating a new user
CREATE USER 'asusi_user'#'localhost' IDENTIFIED '123';
Now I want to grant select privilege to the created user
GRANT select on `asusi_database`.* 'asusi_user'#'localhost'
And here I'm getting an error: 'Access denied for user 'asusi_admin'#'localhost' to database 'asusi_superdb'
Should I relogin as root and explicitly grant access to this database to a asusi_user
GRANT ALL PRIVILEGES ON `asusi_database`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
and then relog in as asusi_admin and run the command again
GRANT select on `asusi_database`.* 'asusi_user'#'localhost'
this time it gives me no error and user asusi_user can read database asusi_database. Apparently MySQL wants me to explicitly grant access to the user asusi_admin for the every created database via root account. But I don't want to use the root account. I thought that after executing this command
GRANT ALL PRIVILEGES ON `asusi\_%`.* TO 'asusi_admin'#'localhost WITH GRANT OPTION;
user asusi_admin will be able to grant access to other users to the ecery database that stats with 'asusi_' prefix. May be I missed something or this behavior is designed to be that way?
It seems this is a confirmed bug, that was not fixed yet https://bugs.mysql.com/bug.php?id=75097, so nothing you can do right now with it.

ERROR 1045 (28000): Access denied for user (using password: YES)

I am trying to have a simple mysql Database on a server and another database on another server that connects to it.
I have done the following :
Installed mysql-server
Created the database
Created the user with :
CREATE USER admin#'localhost' IDENTIFIED BY 'admin';
Given the privileges to this user with :
GRANT ALL PRIVILEGES ON confWeb.* TO admin#'';
Opened the bind-adress
Now when I launch the command mysql -u admin -p -h <address> from another server, it just tells me again and again :
ERROR 1045 (28000): Access denied for user 'admin'#'X.X.X.X' (using password: YES)
I really have no idea what to do at this point. I think I've tried everything.
I tried putting GRANT OPTION in the end of the GRANT line, I tried allowing a lot of different addresses but nothing worked.
In MySQL, a user is identified by both user and host.
This user:
admin#localhost
is not the same user as
admin#'10.242.167.235'
As one option, you could do this to allow connection:
GRANT USAGE ON *.* TO admin#'10.242.167.235' IDENTIFIED BY 'mysecret' ;
GRANT ALL ON confWeb.* TO admin#'10.242.167.235' ;
For a longer discussion of the MySQL Access Privilege System, including "wildcards", the special meaning of localhost, using IP addresses instead of hostnames, etc.
http://dev.mysql.com/doc/refman/5.7/en/privilege-system.html
I do not really know why, but appareantly, it worked when I used the with grant option and first gave access to the database, and then to its tables.
Here is the list of commands that I entered :
mysql> create user 'admin'#'localhost' identified by 'admin';
mysql> grant all privileges on confWeb to 'admin'#'10.69.101.%' identified by 'admin' with grant option;
mysql> grant all privileges on confWeb.* to 'admin'#'10.69.101.%' identified by 'admin' with grant option;
mysql> flush privileges;
Again, I don't really know why it didn't work before and the answers that I saw look like all the documentation I have seen but it looks my problem was somewhere else.
Use following step:-
CREATE USER 'user name'#'IP or % or localhost' IDENTIFIED BY 'password';
GRANT all privileges ON *.* TO 'user name'#'IP or % or localhost' IDENTIFIED BY 'password' ;
flush privileges;
Here in the place of "IP"; you use remote server ip where you want to connect the server.You can also use "%" for useage databases from any plcae in the world.
Now, in Grant option; In the place of "all privileges" you can given access seperately like as select,alter,update etc.

Set privilages to certain database for newly created user

I have foo_bar_test database existing on my mysql server on host 127.0.0.1.
But there's no user that can access it but root, and I don't want to use root user anywhere in my code. So I created new user, fb_test, and granted him privileges for this database:
create user fb_test#'127.0.0.1' identified by password 'some_password';
grant all on 'foo_bar_test.*' to fb_test#'127.0.0.1';
flush privileges;
Ok, that should work, but when I log in as this user, I don't have any database available!
What's wrong?
I checked it using show grants for fb_test#'127.0.0.1', but it shows some strange results:
grant usage on *.* to fb_test#'127.0.0.1' identified by password '*another_password_dont_know_which_one'
How do I solve this?
you have an error in grant statement. Use the query:
grant all on 'foo_bar_test'.* to fb_test#'127.0.0.1';
In fact your grant command results an error which I think you ignored.

mysql access denied while creating new user

I want to create a new mysql user and database demo in my company. Here is the commands i input in the mysql.exe :
create user 'admin'#'localhost' identified by 'admin';
create database dem;
Everytime i have that response:
access denied for user ''#'localhost' to database.
Actually i refered to that similar question :
MySQL - Access denied for user
Can anyone help please ???
I would suggest creating the database first then you can create a user, and use the GRANT option to allow permissions to that user for whatever you find necessary. However, creating a user first then a database while it's able to "potentially" work, isn't the best practice with MySQL. So you want to effectively do the Steps as such:
Create Database
Create User
GRANT permissions
???
Profit
You have to GRANT access to admin for dem.
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'%' WITH GRANT OPTION;
You may have to also GRANT the same for admin#localhost as well. IIRC if you ever logon remotely with admin you would inherit the base privileges unless otherwise GRANTed
You can find many answers HERE.