【问题标题】:"java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)"“java.sql.SQLException:用户'root'@'localhost'的访问被拒绝(使用密码:YES)”
【发布时间】:2020-03-18 13:51:34
【问题描述】:

无法连接到我的数据库。这给了我一条错误消息“java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)”

这是我的代码:

package youtubetest;
import java.sql.*;

public class YoutubeTest {

        private static final String USERNAME = "root";
        private static final String PASSWORD = "root";
        private static final String CONN_STRING = "jdbc:mysql://localhost:3306/youtube";

        public static void main(String args []) {
            Connection conn = null;

            try {
                conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
                System.out.println("Connected!");
            }catch (SQLException e) {
                System.err.println(e);
            }
        }
}

【问题讨论】:

  • 你能仔细检查你的凭证吗?也许你的数据库名称?

标签: java database connectivity


【解决方案1】:

您的代码中似乎没有问题。 您是否尝试过手动连接数据库以检查此用户和密码是否正确?

如果您使用的是 Windows,请参阅: https://phoenixnap.com/kb/connect-to-mysql-windows-command-line

或 Debian/Ubuntu: https://www.cyberciti.biz/faq/how-to-connect-to-my-mysql-database-server-using-command-line-and-php/

【讨论】:

  • 尚未尝试手动连接到数据库。我试试看
猜你喜欢
  • 2021-01-08
  • 2013-05-07
  • 2014-09-10
  • 2012-08-08
  • 2012-08-11
相关资源
最近更新 更多