I'm trying to connect to remote mysql server in java, from ip 111.111.111.111 to ip 111.111.111.222 with JDBC connector:
conn = DriverManager.getConnection("jdbc:mysql://"+serverAddress+":3306/" + this.dBName + "?" + "user=" + this.userName + "&password=" + this.password + "");
- [email protected] is created in database and GRANTS are working fine.
- user@localhost doesn't exist in database because I think is not neccesary.
- Firewall is allowing connection.
For some reason when I try to start the connection an exception is generated:
java.sql.SQLException: The user specified as a definer ('user'@'localhost') does not exist
but I'm requesting the connection from ip 111.111.111.111
Note: when I write an @ in the username this shows the correct host ip but with an extra @, like this:
java.sql.SQLException: Access denied for user 'user@'@'111.111.111.111' (using password: YES)
So, What am I doing wrong? or how can set the host of the mysql username?
EDIT:
Additionally I've tested by terminal the mysql connection and it works properly: (so@SSS ip is 111.111.111.111)
so@SSS:~$ mysql -h 111.111.111.222 -u user -p dbname
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;
+---------------------+
| Tables_in_dbname |
+---------------------+
| wh_with_customer |
+---------------------+
10 rows in set (0,00 sec)
userdoes't have privilege to connect with mysql. You have to giveuserthe permissionmysql -h111.111.111.111 -uuser -pand see whether you can access to Mysql remotelymysql -h 192.xxx.xxx.xxx -u user -p dbName Enter password: ... Welcome to the MySQL monitor. ... mysql> show tables; +---------------------+ | Tables_in_dbname | +---------------------+ ...| wh_with_customer | +---------------------+ 10 rows in set (0,00 sec)So it really works