Access denied in flyway on deploy to the heroku - java

When attempting to deploy, even with certain password and user, flyway is not allowed to migrate. Can someone help me? follows log error below.
2018-12-10 02:07:55.578 ERROR 4 --- [ main]
o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial
connections of pool. 2018-12-10T02:07:55.579896+00:00 app[web.1]:
2018-12-10T02:07:55.579898+00:00 app[web.1]: java.sql.SQLException:
Access denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com'
(using password: YES) 2018-12-10T02:07:55.579899+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579901+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
2018-12-10T02:07:55.579903+00:00 app[web.1]: at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-java-8.0.13.jar!/:8.0.13]
Invocation of init method failed; nested exception is
org.flywaydb.core.internal.exception.FlywaySqlException:
2018-12-10T02:07:55.611900+00:00 app[web.1]: Unable to obtain
connection from database: Access denied for user
''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using password: YES)
2018-12-10T02:07:55.611902+00:00 app[web.1]:
2018-12-10T02:07:55.611904+00:00 app[web.1]: SQL State : 28000
2018-12-10T02:07:55.611906+00:00 app[web.1]: Error Code : 1045
2018-12-10T02:07:55.611908+00:00 app[web.1]: Message : Access
denied for user ''#'ec2-54-91-197-4.compute-1.amazonaws.com' (using
password: YES) 2018-12-10T02:07:55.611909+00:00 app[web.1]:

Related

Exception While Connecting to mysql db with play framework

I am working with PlayFramework (2.3.x) application. I wanted to connect to a mysql db. Below is the configuration that I had given in application.conf:
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.username=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName
When I run the application I am getting the following exception
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
at play.api.Configuration.reportError(Configuration.scala:743)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238)
at scala.collection.immutable.List.map(List.scala:273)
at play.api.db.BoneCPPlugin.onStart(DB.scala:238)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.api.Play$.start(Play.scala:90)
at play.core.StaticApplication.<init>(ApplicationProvider.scala:55)
at play.core.server.NettyServer$.createServer(NettyServer.scala:253)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:289)
at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:284)
at scala.Option.map(Option.scala:146)
at play.core.server.NettyServer$.main(NettyServer.scala:284)
at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.sql.SQLException: Access denied for user ''#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1665)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
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:400)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240)
... 18 more
I have my db created and I am able to use with mysql console.
I have my persistence.xml placed in my conf/META-INF. Below is the persistence.xml
I have root user with all privileges.
Could anyone help me with this?
According to the docs for Play 2.3.x, the correct configuration is db.default.user and not db.default.username. That is probably the cause of the exception. So change your configuration to:
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.user=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName
You are not passing a login, as indicated by the line
Caused by: java.sql.SQLException: Access denied for user ''#'localhost' (using password: YES)

JHipster with Liquibase in production

I'm deploying a JHipster app with the production profile for the first time and i want Liquibase to initialize the database with the correct tables/rows.
However when starting jhipster with the production profile it only results in an exception that say's its unable to connect to MySQL.
Caused by: java.sql.SQLException: Access denied for user 'myusername'#'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
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:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:316)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:518)
... 31 common frames omitted
The error says it unable to connect for user (replaced it with 'myusername' for this post) and that no password is used for the connection. This is where the problem is, a password should be used for the connection but somehow this is not picked up from the configuration. The relevant parts of the configuration:
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&characterEncoding=utf8&useSSL=false
name:
username: myusername
password: SuperSecretPassword
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
liquibase:
contexts: prod
password: SuperSecretPassword
I've added the password to the liquibase.password property myself but that didn't change anything. In other posts the solution was to not set a password for the database user but that is not my preferred option.
Does anyone know how to get this working?
I found out what was wrong. Is used ${spring.datasource.password} to reference the database password in the liquibase.password field but that apparently doesn't work.

postgres server refuses to connect to heroku

I've set up a remote postgresql database for a gradle app that I'd like to deploy on Heroku. When running my app on my machine it works fine. However, I had a hard time connecting to the database that I've set up on Heroku, so I thought I'd just try to connect to my remote database. This is the error that showed up in my app log:
2016-08-18T13:28:12.606715+00:00 app[web.1]: [JarClassLoader] INFO: findResource(): unable to locate "org/postgresql/translation/messages_en.properties"
2016-08-18T13:28:12.609362+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2016-08-18T13:28:12.609487+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2016-08-18T13:28:12.609542+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2016-08-18T13:28:12.609642+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498)
2016-08-18T13:28:12.609715+00:00 app[web.1]: at com.simontuffs.onejar.Boot.main(Boot.java:161)
2016-08-18T13:28:12.609970+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
2016-08-18T13:28:12.610011+00:00 app[web.1]: at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:239)
2016-08-18T13:28:12.610060+00:00 app[web.1]: at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
2016-08-18T13:28:12.610112+00:00 app[web.1]: at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:127)
2016-08-18T13:28:12.610162+00:00 app[web.1]: at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
2016-08-18T13:28:12.610440+00:00 app[web.1]: at org.postgresql.Driver.connect(Driver.java:282)
2016-08-18T13:28:12.610602+00:00 app[web.1]: at net.bethydiakabana.mbta.MbtaApplication.run(MbtaApplication.java:79)
2016-08-18T13:28:12.611050+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused
2016-08-18T13:28:12.611072+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method)
2016-08-18T13:28:12.611122+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
2016-08-18T13:28:12.611146+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
2016-08-18T13:28:12.611170+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
2016-08-18T13:28:12.611286+00:00 app[web.1]: at org.postgresql.core.PGStream.<init>(PGStream.java:61)
2016-08-18T13:28:12.611331+00:00 app[web.1]: ... 23 more
2016-08-18T13:28:12.688094+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T13:28:12.703273+00:00 heroku[web.1]: State changed from starting to crashed
I've read that I needed to change the permissions in the postgres configuration files yet I kept getting the same errors. What would be the best way to fix this on a windows machine?
EDIT:
I've set up a heroku postgres database to see if that would help. I'm not sure if it's still having connection issues as well as locating the main class. Would it still be worth connecting to my original database? This is the error that I'm getting now:
Starting process with command `java -Ddw.server.connector.port=37275 -Ddw.database.user=mmcyajlpsbacac -Ddw.database.password=C6nrfQzuoS2ZEMDaTqVEssPDxa -Ddw.database.url=jdbc:postgresql://ec2-54-235-254-199.compute-1.amazonaws.com:5 432/d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo de=require $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml`
2016-08-18T17:25:22.842387+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-08-18T17:25:22.846667+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-08-18T17:25:23.220849+00:00 app[web.1]: Error: Could not find or load main class 432.d8hvhhr0h3hr8d?user=mmcyajlpsbacac&password=C6nrfQzuoS2ZEMDaTqVEssPDxa&sslmo
2016-08-18T17:25:23.317758+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T17:25:23.331809+00:00 heroku[web.1]: State changed from starting to crashed
Here is a snippet of my yaml configuration that's read by the configuration class:
server:
type: simple
applicationContextPath: /application
adminContextPath: /admin
connector:
type: http
port: 8080
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: someusername
# the password
password: somepassword
# the JDBC URL
url: jdbc:postgresql://host:port/dbname?user=username&password=password
Here is my procfile:
web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.user=$JDBC_DATABASE_USERNAME -Ddw.database.password=$JDBC_DATABASE_PASSWORD -Ddw.database.url=$JDBC_DATABASE_URL $JAVA_OPTS -jar build/libs/mbta-tweets.jar server config.yaml
This message:
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused
Suggests that you are trying to connect to a database on localhost on Heroku, which is certainly not correct. Can you show how you've configured your database connection in the Java code?

Caused by: java.sql.SQLException: Access denied

I have a Java application and I want to access my local database which is a MySQL database, but I have this exception:
Caused by: java.sql.SQLException: Access denied for user
'root'#'localhost' (using password: YES)
I tried to execute this command from MySQL command line client:
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'root'#'localhost' IDENTIFIED BY 'myPass';
But it didn't solve my problem and the exception still appears.
This my connection configuration "database.properties" file:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/mydb
jdbc.username=root
jdbc.password=myPass

Heroku App (play) working fine locally, then not saving to database on server

On Heroku using Play V2. Everything works fine when tested locally, but then when I deploy to Heroku and attempt to save to a PostgreSQL database I get the following error.
In my Procfile I have this.
web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver
Here are my Heroku Error Logs:
2012-04-03T18:16:05+00:00 app[web.1]: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[PersistenceException: Error getting sequence nextval]]
2012-04-03T18:16:05+00:00 app[web.1]: ! #6a0gdoh95 - Internal server error, for request [POST /users] ->
2012-04-03T18:16:05+00:00 app[web.1]: at play.core.ActionInvoker$$anonfun$receive$1.a
2012-04-03T18:16:05+00:00 app[web.1]: [error] application -
2012-04-03T18:16:05+00:00 app[web.1]:
2012-04-03T18:16:05+00:00 app[web.1]:
2012-04-03T18:16:05+00:00 app[web.1]: at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:63) [play_2.9.1-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]: at play.core.ActionInvoker.apply(Invoker.scala:61) [play_2.9.1-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.loadMoreIds(SequenceIdGenerator.java:163) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.nextId(BeanDescriptor.java:1218) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.getMoreIds(SequenceIdGenerator.java:213) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebeaninternal.server.persist.DefaultPersister.setIdGenValue(DefaultPersister.java:1304) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]: at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor-2.0.jar:2.0]
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.nextId(SequenceIdGenerator.java:118) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: Caused by: javax.persistence.PersistenceException: Error getting sequence nextval
2012-04-03T18:16:05+00:00 app[web.1]: at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:403) ~[ebean-2.7.3.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1810) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2077) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "user_seq" does not exist
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:498) ~[postgresql-8.4-702.jdbc4.jar:na]
2012-04-03T18:16:05+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "user_seq" does not exist
Seems to indicate that your database is missing some tables. Make sure that your schema is correct. You can get a console to your DB using heroku pg:psql.
A good practice is setting up postgres locally from scratch and make sure that all of the steps to do so are automated by your application or scripts so that it is more difficult to forget things like this.
I have described the ID column like below and passed the error.
#Id
#SequenceGenerator(name = "UserSequence", sequenceName = "\"USER_SEQ\"", allocationSize = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "UserSequence")
#Column(name = "\"USER_ID\"")
Long userId;

Categories

Resources