java.sql.SQLException: Access denied for user - mysql

I want to create an user that can access from any hosts to Mysql server
I use
create user abc#10.10.131.17 identified by 'abc123'
and
grant all privileges mydb.* to 'abc'#'%';
But when i run client,the error occurs:
"java.sql.SQLException: Access denied for user 'abc'#'10.10.0.7' (using password: YES)
help me,please!

One obvious guess would be that you didn't do FLUSH PRIVILEGES; after issuing GRANT statement.
Another obvious guess (not sure if typo in the question) is that syntax of GRANT is GRANT ALL PRIVILEGES ON mydb.* TO 'abc'#'%';, with ON in it.

You have created an user with allowing IP 10.10.131.17 and you are trying to connect MySQL Server from IP 10.10.10.7. So it won't work.
To access MySQL Server you have to create user allowing IP 10.10.10.7 or allowing all IPs using %.
CREATE USER `abc`#`10.10.10.7` IDENTIFIED BY 'abc123'
GRANT ALL PRIVILEGES mydb.* TO `abc`#`10.10.10.7`;
OR
CREATE USER `abc`#`%` IDENTIFIED BY 'abc123'
GRANT ALL PRIVILEGES mydb.* TO `abc`#`%`;

Related

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.

ACCESS denied error while GRANTing privileges

I want to allow remote connection from a certain IP.
I have a use coszi_crawl and DB name is same too.
I am logged into server using coszi_crawl user.
I have run this command
GRANT ALL PRIVILEGES ON coszi_crawl.* TO 'coszi_crawl'#'39.32.%' IDENTIFIED BY 'abcqwe' WITH GRANT OPTION;
But this is giving me this error
ERROR 1044 (42000): Access denied for user 'coszi_crawl'#'localhost' to database 'coszi_crawl'
P.S.:
Though I can access coszi_crawl DB from Browser using PHPmyadmin with user coszi_crawl
How can I can solve this problem?
You should use the root account on your database server to update the priviledges, by default the user coszi_crawldoes not have access to granting priviledges on databases.
It means You don't have GRANT OPTION privilege. Login to user having GRANT OPTION privileges, only that user can give grant to other users.
Generally or by default root user has all the privileges so use that user.
Grant privilege

Connection failed: Access denied for user

I am trying to access database on remote server with normal user (testuser) with no GRANT privileges. When I try to access the database using the above user I get the following error:
Access denied for user 'testuser'#'%' to database 'test_db'
I do not have any database interface to directly grant privileges to this user. I have SSH root access to the server. How do I grant privileges to this user?
Login to mysql command line interface with your root user. Run the below commands to give access
GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Allow GRANT permission to MySQL User

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;

Access denied for mysql user

I get this error when I try to access my database via the user 'spot'#'localhost' identified by its password.
PermissionsError: (1045, "Access denied for user 'spot'#'localhost' (using password: YES)", None)
I create this user using these two lines:
create user 'spot'#'localhost' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'#'localhost';
When I run this code locally, it works fine. When I run this code on a different machine, I get the aforementioned error.
Yet when I run show grants for 'spot'#'localhost' on both machines, they both give me the same output:
GRANT ALL PRIVILEGES ON *.* TO 'spot'#'localhost' IDENTIFIED BY PASSWORD '*196BDEDE2AE4FRO4CA44C47D54D78478C7E2BD7B7'
How can I debug this access problem?
Yo need to grant privileges not only from localhost, run this querys:
create user 'spot'#'%' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'#'%';
flush privileges;
This allow the user to connect from ANY ip, you can replace the % with the ip of your server.