Fri Sep 09 00:56:14 CST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:875)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1712)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.jakey.util.DbUtil.getCon(DbUtil.java:19)
at com.jakey.util.DbUtil.main(DbUtil.java:31
代码
package com.jakey.util;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil {
// 定义数据库驱动程序
private static final String driver = "com.mysql.jdbc.Driver";
// 数据库连接地址
private static final String url = "jdbc:mysql://localhost:3306/db_courseselect?useUnicode=true&characterEncoding=utf-8";// library表示数据库
private static final String user = "root";
private static final String password = "LWZ222MESSI";
private static Connection connection = null;
// 连接数据库
public DbUtil(){
// 数据库操作可能出现异常
try {
Class.forName(driver);
System.out.println("加载驱动文件成功!");
connection = DriverManager.getConnection(url, user, password);
System.out.println("获得连接对象成功!");
} catch (Exception exception) {
exception.printStackTrace();
System.out.println("数据库连接失败");
} finally {
}
}
public static Connection getConnection() {
return connection;
}
public static void close(Connection connection ) throws Exception {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
// TODO: handle exception
throw e;
}
}
}
}
你这个默认开启了SSL连接,“You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.”应该在数据库中设置 useSSL=false就可以了。
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) 错误在这里! 在user表里面新增数据
如果是远程你的ip为192.168.1.89 则为
CREATE USER 'root'@'192.168.1.89' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON . TO root@'192.168.1.89';
或参考
http://www.javaweb1024.com/info/985.jspx
这个错误其实对运行项目没影响才对吧。 他是意思是你安装了mysql,但是没有修改mysql的密码。 修改下root的密码就好了。
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
错误提示已经很明显了,只需要按照
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
进行修改即可。
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) 错误在这里! 在user表里面新增数据
如果是远程你的ip为192.168.1.89 则为
CREATE USER 'root'@'192.168.1.89' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON . TO root@'192.168.1.89';
或参考
http://www.javaweb1024.com/info/985.jspx