MySQL Access denied for user 'User'#'localhost' (using password: YES) - mysql

I connected a MySQL database for a project (java web application) in netbeans. I created MySQL server with correct login details as root and created a database. I connected my database to the project, but when I am running the application it was showing error in the browser as:
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'User'#'localhost' (using password: YES)
root cause
java.sql.SQLException: Access denied for user 'User'#'localhost' (using password: YES)
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.
Entry in the log file is:
java.sql.SQLException: Access denied for user 'User'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.apache.jsp.Login_jsp.cn(Login_jsp.java:114)
at org.apache.jsp.Login_jsp._jspService(Login_jsp.java:589)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
I am tired in few ways as mentioned in some other forms but not use.

You didn't create the user 'bkUser'#'localhost' correctly.

I found solution, When I was using sql statement for grant privileges i used 'user#%' because of that it was not working. Correct sql statement was:
GRANT ALL PRIVILEGES ON dbname.* TO 'User'#'localhost' IDENTIFIED BY 'Pass' WITH GRANT OPTION;

Related

Problems connecting to a MariaDB server: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)

I am trying to connect a Spring Boot Application to my MariaDB server which is up and running. I am getting the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource
...
Caused by: liquibase.exception.DatabaseException: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
Now I've seen that similar questions have been asked on Stackoverflow before, and I tried the most common approaches, like granting all privileges:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY '%password%' WITH GRANT OPTION;
And removing the password for the root user:
SET PASSWORD FOR root#localhost=PASSWORD('');
None of these approaches worked so far. I cannot really change the .properties file, but from what I can see a password is generated, encrypted and stored every time the application runs:
connection.driver_class = com.mysql.jdbc.Driver
connection.url = jdbc:mysql://127.0.0.1:3306/local02?useSSL=true
connection.username = root
connection.password = ../../config/local/dbkey.txt
connection.pool_size = 200
It's important to highlight that I am experiencing this problem just on MacOS, on Windows (same files, same DB, same IDE) doesn't arise.
Is there anything else I can try?
As far as I know Spring does not allow to use the root user of mariaDB. You must create a new user and grant priviledges.

database configuration for siremis ERROR: SQLSTATE[HY000] [1045] Access denied for user 'siremis'#'localhost' (using password: YES)

ERROR: SQLSTATE[HY000] [1045] Access denied for user 'siremis'#'localhost' (using password: YES).
I amgetting this error during the SIREMIS Setup in the browser. Any ideas on hoiw to resolve this ? I am wasting all my time on this since a week.
Likely you missed the installation step for granting access for siremis user to MySQL server:
https://kb.asipto.com/siremis:install51x:main#database_configuration
enter this in mysql command line via root user:
GRANT ALL PRIVILEGES ON siremis.* TO siremis#localhost IDENTIFIED BY 'siremisrw';

Play scala - oauth2 provider mysql issue

AIM:
I am trying to implement the oauth2 in my application using Play framework 2.3, scala language and MySQL.
WHAT I DID:
I tried to use the scala-oauth2-provider. The given sample is working fine with PostgreSQL. But I want to implement this with MySQL.
WHAT I TRIED:
I have added the below dependencies in the build.sbt
"mysql" % "mysql-connector-java" % "5.1.18",
jdbc
and I removed the below dependency in the given sample.
"org.postgresql" % "postgresql" % "9.3-1100-jdbc41"
Changed the DB configuration in the application.conf
#db.default.url="jdbc:mysql://localhost/oauth"
db.default.url="jdbc:mysql://localhost:3306/oauth"
db.default.driver="com.mysql.jdbc.Driver"
db.default.user="root"
db.default.pass="root"
db.default.host="localhost"
ISSUE:
I am facing the below issue.
[error] - c.j.b.h.AbstractConnectionHook - 14:16:25.117 - Caller+0 at com.jolbox.bonecp.hooks.AbstractConnectionHook.onAcquireFail(AbstractConnectionHook.java:77)
- Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: null.Message:Access denied for user 'root'#'localhost' (using password: YES)
[error] - application - 14:16:25.131 - Caller+0 at play.api.LoggerLike$class.error(Logger.scala:141)
-
! #6nmjm0p14 - Internal server error, for (GET) [/] ->
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.11-2.3.4.jar:2.3.4]
at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.11-2.3.4.jar:2.3.4]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.11-2.3.4.jar:2.3.4]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.11-2.3.4.jar:2.3.4]
at scala.collection.immutable.List.map(List.scala:273) ~[scala-library-2.11.6.jar:na]
Caused by: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943) ~[mysql-connector-java-5.1.18.jar:na]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113) ~[mysql-connector-java-5.1.18.jar:na]
I have given the correct mysql credential only and also I have the database named oauth. Even though it throws "Access denied for user 'root'#'localhost' (using password: YES)" error.
Can anyone help me to fix this?
Please take the following actions:
In mysql, under root user:
CREATE USER 'test1'#'localhost' IDENTIFIED BY 'mypass';
CREATE DATABASE oauth;
GRANT ALL ON oauth.* TO 'test1'#'localhost';
Change credentials in your conf/application.conf:
db.default.user="test1"
db.default.pass="mypass"
Then run your application. This should work.
You have
Access denied for user 'root'#'localhost' (using password: YES)
check your credentials

JDBC / MYSQL: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: NO)

With this code
String url = "jdbc:mysql://localhost/mysql";
Connection con = DriverManager.getConnection(url, "root", "");
I get the following exception.
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyTest1.main(MyTest1.java:29)
I logged into the database using the command tool with root and no password. I was able to telnet to the database and I get this message
N
5.5.17-log
7{*Zj%u☻ǧ|tR}=Vz'L,6imysql_native_password"
Even I also faced the same problem. But, in my application, I did one mistake like I forgot to give password. You can try to manually login to your MySQL and check what is the username and password you are using to log in. That same details you can use in the URL. Better to give database names also. As like below
For MySQL:
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url, "root", "");
In the above, you forgot to give the port number of MySQL. You can check once your MySQL has a port number or not. By default, MySQL port number is 3306. Better to create and use your own database.
If the above one is not working try for GRANT all privileges to user root on your user database. To grant all privileges below is the query,
GRANT ALL PRIVILEGES ON mysql.* TO 'root'#'localhost' WITH GRANT OPTION;
or else
GRANT ALL PRIVILEGES ON mysql.* TO 'root'#'localhost' IDENTIFIED BY 'root';
'root'#'localhost' is different from 'root'#'%'. It may still be a permissions issue.
I suggest that you log in through the console, create a 'test'#'%' user with a password, and give it all permissions. You can learn how to do that here.
It turned out to be some problem with my MYSQL installation. I uninstalled the AMP package I was using and installed XAMPP instead and it works.

Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)

I am trying to add Sonar to my Continuous Integration build system. I am using ANT as my build script and I am using the sonar-ant-task-1.1.jar for sonar to generate the reports based on my source code in SVN.
Problem
When the build runs and hits the sonar ant task I get the exception as follows:
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at org.sonar.jpa.session.DriverProxy.connect(DriverDatabaseConnector.java:160)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.sonar.jpa.session.DriverDatabaseConnector.getConnection(DriverDatabaseConnector.java:95)
at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:185)
... 40 more
What I have done
1. Install MySQL database.
2. Create the sonar database, sonar user, and grant permissions by using the script provided in the sonar installation
**CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;**
3. Added the following to my build script
4. Added the following external variables in Jenkins Freestyle build project
sonar.jdbc.url=jdbc:mysql://10.120.21.12:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://10.120.21.12:9000/
5. I was also available to connect to the database through my sql client tool to verify that the database, user and permissions statements were executed correctly.
However when Jenkins runs the build it does not seem to know how to connect to the MySQL database.
Any thoughts?
The solution was to run the following command:
GRANT ALL ON *.* TO 'sonar'#'%';
The right solution is this:
GRANT ALL PRIVILEGES ON `sonar`.* TO 'sonar'#'localhost';
As explained here, connections to localhost occur over a UNIX domain socket. You are likely logging in as an anonymous user to localhost (e.g. ''#localhost).
I just tried it with sonar 4.5.2 with grants only on sonar.* and its definitely not working.
It looks like sonarqube requires additionnal privileges to work, personnaly i haven't identified which ones yet, and i'm still using a grant all on the database.