程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> mysql-JAVA SSH開發的網站後台部署到阿裡服務器時,連不上數據庫

mysql-JAVA SSH開發的網站後台部署到阿裡服務器時,連不上數據庫

編輯:編程解疑
JAVA SSH開發的網站後台部署到阿裡服務器時,連不上數據庫

現象
1)網站在自己的開發測試環境運行正常
2)在部署環境中,網站在訪問數據庫的時候,tomcat報錯如下:
另:開發環境跟部署環境的mysql的characterset不一樣(具體見下面的log),會導致這個問題嗎?

 2016-07-13 19:18:38 [com.mchange.v2.resourcepool.BasicResourcePool]-[INFO] An ex
ception occurred while acquiring a poolable resource. Will retry.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password
: YES)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:926)
        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(My
sqlIO.java:1748)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1288)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2506)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2
539)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:344)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
erDataSource.java:134)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:182)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
on(WrapperConnectionPoolDataSource.java:171)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
Pool.java:1014)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
ePool.java:32)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicRe
sourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:547)

基本情況
1)部署環境
1.1)阿裡服務器操作系統: 32位,windows server standard
1.2)服務器上部署apache-tomcat-7.0.34
1.3)同一個服務器上安裝mysql服務器: 5.6.31(32位)//實在找不到哪裡有5.6.14可以下載
1.4)同一個服務器上用mysql訪問數據庫正常,端口,賬號,密碼都沒有問題

#c3p0jdbc
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc:mysql://127.0.0.1:3306/lgs?useUnicode=true&characterEncoding=UTF-8
database.username=root
database.password=admin 
 mysql> status
--------------
mysql  Ver 14.14 Distrib 5.6.31, for Win32 (AMD64)

Connection id:          1052
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.6.31 MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    gbk
Conn.  characterset:    gbk
TCP port:               3306
Uptime:                 21 hours 58 min 13 sec

Threads: 1  Questions: 2003  Slow queries: 0  Opens: 71  Flush tables: 1  Open t
ables: 64  Queries per second avg: 0.025

2)開發測試環境
2.1)windows 7,64位
2.2)JDBC driver: mysql-connector-java-5.1.30.jar
2.3)apache-tomcat-7.0.34
2.4)mysql服務器:5.6.14 (64位)

 mysql> status;
--------------
C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe  Ver 14.14 Distrib 5.6.14,
 for Win64 (x86_64)

Connection id:          1
Current database:
Current user:           root@localhost
SSL:                    Not in use
Using delimiter:        ;
Server version:         5.6.14 MySQL Community Server (GPL)
Protocol version:       10
Connection:             localhost via TCP/IP
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:               3306
Uptime:                 9 hours 54 min 31 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 67  Flush tables: 1  Open tabl
es: 60  Queries per second avg: 0.000
--------------

最佳回答:


嘗試了各種方法,最好重裝了一個mySql server,搞定

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved