简体   繁体   English

Java连接到MySQL数据库错误

[英]Java Connecting to a MySQL database error

I have been having a bit of trouble with connecting to my database. 我在连接数据库时遇到了麻烦。 I connect to the same database on my website and it works, so I know it's probably something to do with the path to the database in my Java code. 我连接到网站上的同一数据库,并且可以正常工作,因此我知道这可能与Java代码中数据库的路径有关。

Connection con = DriverManager.getConnection("jdbc:mysql://ultraboodog.com:3306/ultraboo_lr", "ultraboo_root", "password");

I have no clue why it isn't working, and I am getting this error: 我不知道为什么它不起作用,并且出现此错误:

java.sql.SQLException: Access denied for user 'ultraboo_root'@'S010650465d6c5d19.ss.shawcable.net' (using password: YES)

Any help would be much appreciated :) 任何帮助将非常感激 :)

EDIT: I am also using the mysql-connector-java plugin to connect to the database, it is made by Oracle. 编辑:我也在使用mysql-connector-java插件来连接数据库,它是由Oracle制造的。

MySQL access is determined by username, source address, and password. MySQL访问由用户名,源地址和密码确定。 Most hosting services restrict where the user is allowed to connect from, but allow you to add locations in their panel (like cPanel). 大多数托管服务会限制允许用户连接的位置,但允许您在其面板中添加位置(如cPanel)。

If the server is entirely under your control and you have direct MySQL access, the GRANT documentation for MySQL shows how to do it, for example: 如果服务器完全在您的控制之下,并且您具有直接的MySQL访问权限,则MySQL的GRANT文档说明了如何执行此操作,例如:

CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';

The "localhost" part could be a hostname, IP address, or wildcard such as %.example.com or 192.168.1.%. “ localhost”部分可以是主机名,IP地址或通配符,例如%.example.com或192.168.1。%。 In your case since you are connecting from a cable provider, if your IP address is reasonably stable, the most secure approach is to add your exact IP address, and when it changes (hopefully rarely), you update the MySQL permissions to match. 在这种情况下,由于您是从电缆供应商处进行连接的,因此,如果您的IP地址相当稳定,则最安全的方法是添加确切的IP地址,并且当它更改时(希望很少),您将更新MySQL权限以进行匹配。

The security implications of allowing SQL access to the Internet is something you should not consider lightly, though. 但是,您不应轻易考虑允许SQL访问Internet的安全性。

java.sql.SQLException: Access denied for user 'ultraboo_root'@'S010650465d6c5d19.ss.shawcable.net' (using password: YES)

As you have mentioned problem is with creating connection with the database itself. 如前所述,问题在于与数据库本身建立连接。 Statement 声明

Try something like this: 尝试这样的事情:

conn = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=rootpassword"); 
s = conn.createStatement();
int result = s.executeUpdate("CREATE DATABASE databasename");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM