我試圖連接到遠程MySQL服務器在Java中,從IP 111.111.111.111到ip 111.111.111.222使用JDBC連接器:設置MySQL用戶主機
conn = DriverManager.getConnection("jdbc:mysql://"+serverAddress+":3306/" + this.dBName + "?" + "user=" + this.userName + "&password=" + this.password + "");
- [email protected] .111.111在數據庫中創建,GRANTS工作正常。
- user @ localhost在數據庫中不存在,因爲我認爲這不是必須的。
- 防火牆允許連接。
出於某種原因,當我嘗試啓動生成異常的連接:
java.sql.SQLException: The user specified as a definer ('user'@'localhost') does not exist
但我請求從IP 111.111.111.111連接
注:當我在用戶名中輸入@表示正確的主機IP,但帶有一個額外的@,如下所示:
java.sql.SQLException: Access denied for user '[email protected]'@'111.111.111.111' (using password: YES)
那麼,我在做什麼錯了?或者如何設置mysql用戶名的主機?
編輯:
而且我已經通過終端測試的MySQL連接,並能正常工作:(所以@ SSS IP 111.111.111.111是)
[email protected]:~$ 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)
'user'簡化版,有權限與MySQL連接。您必須授予'用戶'權限 – haifzhan
「,因爲我認爲這不是必須的。」 - 檢查你的假設。 – duffymo
@duffymo因爲我只是遠程連接到數據庫。那麼它是否必要? –