Access denied for user 'root'@'localhost '- Application connects via command but not in Wildfly 10

Asked

Viewed 2,583 times

2

Settings:

  • Wildfly server 10.1.0
  • Mysql 14.14
  • Mysql-Connector- 8.0.15
  • Hibernate 5.2

Permissions granted to the user:

GRANT ALL PRIVILEGES ON bd_billings.* to root@localhost;FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; flush privileges;

With this command, I can connect to the base with the same login and password that are in persistece:

mysql -u root -h localhost -P 3306 -p nomeDaBase

Settings made in Wildfly:

standalone.xml

    <subsystem xmlns="urn:jboss:domain:datasources:4.0">
        <datasources>
            <drivers>
                <driver name="mysql" module="com.mysql">
                    <driver-class>com.mysql.cj.jdbc.Driver</driver-class>
                    <xa-datasource-class>com.mysql.cj.jdbc.MysqlXADataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>

mysql-Connector is in the folder

wildfly-10.1.0.Final modules system layers base with mysql main mysql-Connector-java-8.0.15.jar

wildfly-10.1.0.Final modules system layers base with mysql main module.xml

<module xmlns="urn:jboss:module:1.5" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-8.0.15.jar" />    
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

persistence.xml

      <property name = "hibernate.connection.url"                     value="jdbc:mysql://localhost:3306/nomeDaBase?serverTimezone=UTC"/>


      <property name = "hibernate.connection.username"                value="root"/>      
      <property name = "hibernate.connection.verifyServerCertificate" value="false"/>
          <property name = "hibernate.connection.useSSL"                  value="false"/>
          <property name=  "hibernate.connection.requireSSL"              value="false"/>
          <property name = "hibernate.jdbc.time_zone"                     value="UTC"/>

          <property name = "hibernate.show_sql"                           value="true" />

      <property name = "hibernate.dialect"                            value="org.hibernate.dialect.MySQLDialect" />
      <property name = "hibernate.connection.driver_class"            value="com.mysql.cj.jdbc.Driver" />
      <property name = "hibernate.hbm2ddl.auto"                       value="validate"/>

      <!-- Configuring Connection Pool -->
       <property name="hibernate.c3p0.min_size"                       value="5" />
       <property name="hibernate.c3p0.max_size"                       value="20" />
       <property name="hibernate.c3p0.timeout"                        value="500" />
       <property name="hibernate.c3p0.max_statements"                 value="50" />
       <property name="hibernate.c3p0.idle_test_period"               value="2000" />
                  <property name="hibernate.transaction.factory_class"            value="org.hibernate.transaction.JDBCTransactionFactory"/>
      <property name="hibernate.current_session_context_class"
  value="thread"/>

When deploying on the application’s remote server the error occurs:

2019-02-19 12:23:17,913 ERROR [org.jboss.msc.service.fail]
> (ServerService Thread Pool -- 71) MSC000001: Failed to start service
> jboss.persistenceunit."NomeApp.war#NomeAppApp":
> org.jboss.msc.service.StartException in service
> jboss.persistenceunit."NomeApp.war#NomeAppApp":
> org.hibernate.service.spi.ServiceException: Unable to create requested
> service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:179)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:121)
>   at
> org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:193)
>   at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
>   at java.lang.Thread.run(Thread.java:748)    at
> org.jboss.threads.JBossThread.run(JBossThread.java:320) Caused by:
> org.hibernate.service.spi.ServiceException: Unable to create requested
> service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
>   at
> org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
>   at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
>   at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
>   at
> org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
>   at
> org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
>   at
> org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
>   at
> org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
>   at
> org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161)
>   ... 7 more Caused by:
> org.hibernate.exception.JDBCConnectionException: Error calling
> Driver#connect    at
> org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:105)
>   at
> org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
>   at
> org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
>   at
> org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
>   at
> org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106)
>   at
> org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40)
>   at
> org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
>   at
> org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
>   at
> org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
>   at
> org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
>   at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
>   at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
>   at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
>   at
> org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
>   at
> org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
>   at
> org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
>   ... 19 more Caused by: java.sql.SQLException: Access denied for user
> 'root'@'localhost'    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:835)
>   at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
>   at
> com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
>   at
> com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
>   at
> org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
>   ... 34 more
> 
> 2019-02-19 12:23:17,917 ERROR
> [org.jboss.as.controller.management-operation] (External Management
> Request Threads -- 7) WFLYCTL0013: Operation ("add") failed - address:
> ([("deployment" => "NomeApp.war")]) - failure description: {
>     "WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"NomeApp.war#NomeAppApp\"" =>
> "org.jboss.msc.service.StartException in service
> jboss.persistenceunit.\"NomeApp.war#NomeAppApp\":
> org.hibernate.service.spi.ServiceException: Unable to create requested
> service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
>     Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service
> [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
>     Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
>     Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost'"},
>     "WFLYCTL0412: Required services that are not installed:" => ["jboss.persistenceunit.\"NomeApp.war#NomeAppApp\""],
>     "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined } 2019-02-19 12:23:17,919 ERROR [org.jboss.as.server]
> (External Management Request Threads -- 7) WFLYSRV0021: Deploy of
> deployment "NomeApp.war" was rolled back with the following failure
> message:  {
>     "WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"NomeApp.war#NomeAppApp\"" =>
> "org.jboss.msc.service.StartException in service
> jboss.persistenceunit.\"NomeApp.war#NomeAppApp\":
> org.hibernate.service.spi.ServiceException: Unable to create requested
> service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
>     Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service
> [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
>     Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
>     Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost'"},
>     "WFLYCTL0412: Required services that are not installed:" => ["jboss.persistenceunit.\"NomeApp.war#NomeAppApp\""],
>     "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined 

1 answer

1


Solved!

I performed the following procedures:

Run the commands in mysql:

UPDATE mysql.user SET plugin = 'auth_socket' WHERE User = 'root';
UPDATE mysql.user SET host = '%' WHERE User = 'root';

Open the file (Linux command): vi /etc/mysql/mysql.conf.d/mysqld.cnf

I commented on the line: #bind-address = 127.0.0.1

I restarted mysql: systemctl restart mysql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.