Can anyone tell me how to solve these errors? [duplicate] - mysql

This question already has an answer here:
Exception in thread "main" java.sql.SQLException: Access denied for user ''#'localhost' (using password: NO)
(1 answer)
Closed 2 years ago.
Exception in thread "main" java.sql.SQLException: Access denied for user ''#'localhost' (using password: NO)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.mysql.cj.jdbc.admin.TimezoneDump.main(TimezoneDump.java:70)

Try adding a password and try connecting again.
GRANT ALL ON <database>.* TO '<user>'#'localhost' IDENTIFIED BY '<password>';

Related

Unable to connect to mysql from sts

I have provided the credentials in application.properties to connect to Mysql but spring-boot is failing to take those credentials.
This is my application.properties file:
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost/person_example
spring.datasource.data-username=root
spring.datasource.data-password=password
the error shown in console:
java.sql.SQLException: Access denied for user ''#'localhost' (using password: NO)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.15.jar:8.0.15]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.15.jar:8.0.15]
See docs on common speinh properties here:
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
You need to use spring.datasource.username and spring.datasource.password

Can't connect to MySQL database from java but able to connect from plain MySQL command line

I'm trying to use mwdumper jar to import a wiktionary dump to a db that I created with MAMP Pro. Here is the command that I'm struggling with:
java -jar mwdumper-1.25.jar --format=sql:1.5 /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml --output=mysql://localhost:8889/wiktionay?user=wikiuser&password=wiki2017
Running the jar with this command gives the following:
> [1] 1209
$ Exception in thread "main" java.io.IOException: Access denied for user 'wikiuser'#'localhost' (using password: NO)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:225)
at org.mediawiki.dumper.Dumper.openOutputFile(Dumper.java:211)
at org.mediawiki.dumper.Dumper.main(Dumper.java:96)
Caused by: java.sql.SQLException: Access denied for user 'wikiuser'#'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(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:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:221)
... 2 more
When I simply try to connect to the DB from the terminal, I have no access problem:
$ /Applications/MAMP/Library/bin/mysql -u wikiuser -p
As mentioned in related issues, I checked "Allow network access to MySQL" from the MAMP Interface but still it didn't help. Same issue by using root.
Any idea what's wrong?
Problem is that due to & operator password in the URL gets as separate command while sending URL on terminal. Hence, mysql never gets password.
Use \ to escape & i.e.
--output=mysql://localhost:8889/wiktionay?user=wikiuser\&password=wiki2017
Edited: 04:14 AM, IST
Exception in thread "main" java.lang.IllegalArgumentException:
Expected file stream, got SQL connection?
Try passing stream filename at the end i.e. after --output followed by --format and then /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml

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

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;

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.