Java JDBC Access denied for user

[亡魂溺海] 提交于 2019-11-26 04:56:06

问题


I am trying make a connection to MySQL from my java application and it keeps on saying :

java.sql.SQLException: Access denied for user \'vincent\'@\'x.x.x.x\' (using password: YES)

I have checked in phpmyadmin that vincent can conect from any host and I also have a python script who can connect with the same username/password without any problem

What is the problem ?

Thank you very much

Regards.


回答1:


Try granting all privileges to your user from any machine in mysql:

 grant all on db_name.* to ‘vincent’@'%';

where db_name is your database name ...




回答2:


Here's how I'd GRANT permissions:

create database foobar;
create user foobar identified by 'foobar';
grant all on foobar.* to 'foobar'@'%' identified by 'foobar';
grant all on foobar.* to 'foobar'@'localhost' identified by 'foobar';

You need the user's host machine as well.




回答3:


Use this

GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';

You have to give access to user on db. and yes if you are being using a user defined stored procedure and function then also use

GRANT SELECT ON mysql.proc TO 'db_user'@'%';



回答4:


You have to specify the userid and password while getting connection object:

Connection cn=DriverManager.getConnection("protocol","userid","password");


来源:https://stackoverflow.com/questions/8224898/java-jdbc-access-denied-for-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!