0

So I created a database on my cloud server with the following commands:

mysql> create database app1;
Query OK, 1 row affected (0.02 sec)

mysql> grant all privileges on app1.* TO 'app1'@'localhost' 
identified by 'abcdefg';
Query OK, 0 rows affected (0.02 sec)

then I updated my persistance.xml as follows:

    <persistence-unit name="app1">
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/app1" />
        <property name="javax.persistence.jdbc.user" value="app1" />
        <property name="javax.persistence.jdbc.password" value="abcdefg" />
        <property name="javax.persistence.schema-generation.database.action"
            value="create" />
        <property name="hibernate.show_sql" value="true" />
    </properties>
</persistence-unit>

but I still get the this error when I try to visit the site from a browser:

java.sql.SQLException: Access denied for user 'app1'@'127.0.0.1' (using password: YES)

I verified that the user exists with:

SELECT User FROM mysql.user;

what can be causing this issue??

Ammar Samater
  • 529
  • 2
  • 7
  • 24

1 Answers1

1

The problem is that you have created a user which can be used to connect from the local machine via a local socket only and not via TCP/IP what JDBC is trying to do. You can read JDBC MySQL connection using Unix Socket on how to connect to MySQL using a local socket or create a user for the host 127.0.0.1, which will be used for TCP/IP connections.

Progman
  • 16,827
  • 6
  • 33
  • 48