java.sql.SQLException:拒绝访问用户' winehip' @' localhost' (使用密码:是)

时间:2017-07-07 13:44:37

标签: java mysql minecraft

我已经搜索过类似的问题,寻找解决我问题的方法,因为很多人都遇到了和我一样的问题。但是,没有一个解决方案有帮助,我仍然有相同的错误堆栈。

这是我启动连接的java代码。堆栈清楚地指向conn = DriverManager.getConnection(...);:

的行
package com.wine.plugins.managers.models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class DatabaseModel 
{
    protected static Connection conn = null;

    private static final String url = "jdbc:mysql://localhost/wineships?useSSL=false";
    private static final String username = "wineship";
    private static final String password = "password";

    public DatabaseModel()
    {
        try {
            if(conn == null)
            {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                conn = DriverManager.getConnection(url, username, password);
                if (conn != null) {
                    System.out.println("Connected to the database");
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (InstantiationException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

这是堆栈:

[08:24:25 WARN]: java.sql.SQLException: Access denied for user 'wineship'@'localhost' (using password: YES)
[08:24:25 WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
[08:24:25 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
[08:24:25 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
[08:24:25 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
[08:24:25 WARN]:        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710)
[08:24:25 WARN]:        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
[08:24:25 WARN]:        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2194)
[08:24:25 WARN]:        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2225)
[08:24:25 WARN]:        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
[08:24:25 WARN]:        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
[08:24:25 WARN]:        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
[08:24:25 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[08:24:25 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[08:24:25 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[08:24:25 WARN]:        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[08:24:25 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[08:24:25 WARN]:        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
[08:24:25 WARN]:        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
[08:24:25 WARN]:        at java.sql.DriverManager.getConnection(DriverManager.java:664)
[08:24:25 WARN]:        at java.sql.DriverManager.getConnection(DriverManager.java:247)
[08:24:25 WARN]:        at com.wine.plugins.managers.models.DatabaseModel.<init>(DatabaseModel.java:21)
[08:24:25 WARN]:        at com.wine.plugins.managers.models.ValidBlocksDatabaseModel.<init>(ValidBlocksDatabaseModel.java:10)
[08:24:25 WARN]:        at com.wine.plugins.managers.BlockValidityManager.initialize(BlockValidityManager.java:16)
[08:24:25 WARN]:        at com.wine.plugins.WineShips.onEnable(WineShips.java:12)
[08:24:25 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
[08:24:25 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
[08:24:25 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402)
[08:24:25 WARN]:        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:377)
[08:24:25 WARN]:        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:327)
[08:24:25 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421)
[08:24:25 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382)
[08:24:25 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337)
[08:24:25 WARN]:        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272)
[08:24:25 WARN]:        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544)
[08:24:25 WARN]:        at java.lang.Thread.run(Thread.java:748)

MySQL服务器在Linux上的程序Xampp上的localhost:3306上运行。该代码适用于将从SQL服务器请求数据的Minecraft服务器。

1 个答案:

答案 0 :(得分:1)

我一直在修补phpmyadmin,我发现输入一个地址而不是使用'%'解决了我的问题。我还将“localhost”更改为127.0.0.1 @nigel ren

我的代码现在是:

private static final String url = "jdbc:mysql://127.0.0.1/wineships";
private static final String username = "wineship";
private static final String password = "password";