在liunx上的javaweb后台连接不到数据库 ,但是app可以连接到数据库
 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 **

数据库是安装在liunx上的mysql, 和程序在一台服务器上面,这个数据库在本地可以连上,这台服务器上的别的程序也可以连接到这个数据库.

搞了半天实在不知道怎么办了, 求大神解答

图片说明

3个回答

这是密码错误的提示吧

shane_s
shaneoeo 回复快速递丶walnut: 改成127.0.0.1试过,也是连接不上,请问还有什么解决办法吗
2 年多之前 回复
qq_25048139
快速递丶walnut 你在项目中写的是公网连接, 他肯定会以公网ip访问,如果不需要,可以直接localhost或者本地ip地址
2 年多之前 回复
shane_s
shaneoeo 回复快速递丶walnut: 这个数据库是自己在liunx上安装的, 访问也需要分配权限吗?
2 年多之前 回复
qq_25048139
快速递丶walnut 公网访问需要分配权限吧,
2 年多之前 回复
shane_s
shaneoeo 相同的连接字符串在本地可以连接上
2 年多之前 回复

你说的是不能远程连接吗?如果是的话,
1.
#(执行下面的语句 .:所有库下的所有表 %:任何IP地址或主机都可以连接)
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
“root”用户名
“123”密码
2.设置防火墙

shane_s
shaneoeo 不是远程连接,是同一个服务器,项目和数据库都在这个服务器上,但是线上的项目连接不到这个服务器上安装的数据库了,这个数据库在我本地是可以连接上的.
2 年多之前 回复

把localhost改成IP试试

shane_s
shaneoeo 我的连接字符串里就没有 "localhost" 和 "root" 这两个字段
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐