三月 14, 2019 7:54:19 下午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
严重: create connection SQLException, url: jdbc:mysql://127.0.0.1:3306/test, errorCode 1045, state 28000
java.sql.SQLException: Access denied for user 'tt'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2505)

解决方案 »

  1.   

    druid.properties如下:密码没问题
    # 配置数据库的连接参数
    driverClassName=com.mysql.jdbc.Driver
    #需要解决时区问题
    url=jdbc:mysql://localhost:3306/mybatisdb
    username=root
    password=123456
    # 配置连接池的参数
    initialSize=5
    maxActive=10
    maxWait=3000
    minIdle=3
      

  2.   

    注解注入配置如下:
    public class DuridConfiguration {
        @Value("${driverClassName}")
        private String driver;
        @Value("${url}")
        private String url;
        @Value("${username}")
        private String username;
        @Value("${password}")
        private String password;    /**
         *
         * 提供一个方法,返回 queryRunner
         */
        @Bean
        public QueryRunner createRunner(DataSource dataSource){
            return new QueryRunner(dataSource);
        }    // 如过 Bean 有多个,可以根据 Bean 的方法来具体获取
    //    @Bean
    //    public QueryRunner createRunner(@Qualifier("ds1") DataSource dataSource){
    //        return new QueryRunner(dataSource);
    //    }    @Bean("ds1")
        public DataSource createDataSource(){
            DataSource ds = null;
            try {
                Properties pro = new Properties();
                pro.setProperty("driverClassName",driver);
                pro.setProperty("url",url);
                pro.setProperty("username",username);
                pro.setProperty("password",password);
                ds = DruidDataSourceFactory.createDataSource(pro);
            }catch (Exception e){
                e.printStackTrace();
            }
            return ds;
        }
    }
      

  3.   

      看你的配置mysql与项目都在同一台电脑上,也不涉及远程连接问题,楼主试试用命令行的模式连接mysql,确保你的用户名与密码没有问题.
      

  4.   

    1、把127.0.0.1改为localhost,有时候认localhost不认127.0.0.1。
      

  5.   

    2、确定有test库,而不是tt库。
    3、确定是3306端口。
    4、确定账号密码没错。
    5、建议先用工具连接(Navicat之类的),确定上面的参数都没啥问题,再代码连接
      

  6.   

    java.sql.SQLException: Access denied for user 'tt'@'localhost' (using password: YES)
    应该是数据库的用户名或密码错误吧
      

  7.   

    你properties里信息完全不一致,pro里用户是root,怎么报错是tt?库名也不一样,你是不是把pro文件的路径搞错了?
    你先确定tt该用户密码是否正确,在确定tt用户是否有权限访问test数据库。
      

  8.   

    楼主你好啊,下载了ssm在线考试的源码,有些问题想向你请教,希望与你取得联系呀