开发者社区> 问答> 正文

线上的java项目访问不到线上数据库,但是这个数据库我本地可以连接到,求解。报错

"

 java.lang.Exception: 数据库连接失败:Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: 'java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)'.

** BEGIN NESTED EXCEPTION **

java.sql.SQLException MESSAGE: Access denied for user 'root'@'localhost' (using password: YES)

STACKTRACE:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2924) at com.mysql.jdbc.Connection.<init>(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556) at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) at com.xabeiying.lefu.server.utils.ConnectionToMysql.getConnectionDB(ConnectionToMysql.java:103) at com.xabeiying.lefu.server.dao.ZFDao.getzfbddh11sc(ZFDao.java:58) at com.xabeiying.lefu.server.action.GetJSWYWXAction.doPost(GetJSWYWXAction.java:217) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

** END NESTED EXCEPTION **

这个项目的app端可以连接到数据库(登录注册),但是后台连接不到数据库(无法登录) 求大神解答!

这个配置文件是没有问题的,我本地也在用这个配置文件,本地和线上是一个数据库.
数据库是mysql,安装在liunx上,项目也在同一台服务器上面.
现在这个服务器上的其他项目连接这个数据库没有问题,只有这个项目的后台连接不上数据库!

"

展开
收起
因为相信,所以看见。 2020-05-27 12:59:11 1220 0
1 条回答
写回答
取消 提交回答
  • 阿里,我所有的向往

    "

    可能是没有给mysql root用户设初始密码吧

    ######

    是不是你把本地连接给关了

    ######

    select user, host from mysql.user 看看你就知道了

    ######

    mysql server 的设置里面,ip 没有指定 localhost 吧。如果用 0.0.0.0 用 localhost 就能访问吧

    ######

    <img src=""/img/bVZ6fL?w=234&h=74"" alt=""clipboard.png"" title=""clipboard.png"" />

    ######

    <img src=""/img/bV0gz8?w=515&h=205"" alt=""图片描述"" title=""图片描述"" />

    我的是这样 通过mysql命令行或者管理工具可以连接,但是通过启动java项目就连接报错(如图) 额,什么 鬼呢?

    ######

    先去部署的机器上面,使用mysql客户端工具,用数据库用户和密码,保证连上mysql;再考虑你的程序问题

    ######

    老哥解决了吗,我也碰到这个问题

    "
    2020-05-27 16:24:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
DTCC 2022大会集锦《云原生一站式数据库技术与实践》 立即下载
阿里云瑶池数据库精要2022版 立即下载
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载