我想連接我的本地MYSQL數據庫,它與XAMP服務器一起安裝。我創建了一個新用戶,即「NewUser」,密碼是「password」。我將所有PRIVILEGES授予此用戶。訪問被拒絕用戶'root'@'localhost'(使用密碼:YES)
我使用用戶「root」(該用戶沒有密碼)編寫與數據庫連接的代碼。 其連接。像波紋管..
return DriverManager.getConnection("jdbc:MySql://localhost/database_name","root","");
現在我寫的代碼由另一個用戶即「NEWUSER」及其pasword「密碼」
return DriverManager.getConnection("jdbc:MySql://localhost/database_name","NewUser","password");
,但它不是與連接相同的數據庫進行連接。 在控制檯中的錯誤是
java.sql.SQLException: Access denied for user 'NewUser'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor207.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:214)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)
at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java:28)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
我給主機類型,同時提供特權給該用戶,作爲「任意主機的」,即,「%」。
如果我改變它爲「本地主機」或「127.0.0.1」它的工作。
那麼我如何使用我的數據庫與「anyhost」特權給像「NewUser」這樣的特定用戶。
如果我在這裏取得成功,然後我在連接到客戶端實時數據的基礎上成功..
感謝大家,請讓我離開這一個.....
你可以使用'mysql -u NewUser -h localhost -p'連接控制檯嗎? – Sal00m 2013-08-28 07:26:11