简体   繁体   English

无法创建与数据库的连接(ColdFusion)

[英]Could not create connection to database (ColdFusion)

I'm creating a simple CRUD application via ColdFusion. 我正在通过ColdFusion创建一个简单的CRUD应用程序。 I'm going to ColdFusion Administrator Panel at http://localhost:8600/CFIDE/administrator/index.cfm , and adding a "New Data Source". 我要去http://localhost:8600/CFIDE/administrator/index.cfm ColdFusion管理员面板,并添加一个“新数据源”。 But I get the following error: 但是我收到以下错误:

Connection verification failed for data source: dsnMyVariable
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 
The root cause was that: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

DSN SQLNonTransientConnectionException错误

Update: 更新:

After installing MySQL 8, I got the exact same error message when creating a DSN. 安装MySQL 8后,我在创建DSN时收到完全相同的错误消息。 It seems to be a compatibility issue with MySQL 8. Checking the System Support Matrix for ColdFusion 2016 only shows MySQL 5.7, so MySQL 8 probably isn't supported or compatible with the built in drivers. 这似乎是MySQL 8的兼容性问题。检查ColdFusion 2016系统支持矩阵只显示MySQL 5.7,因此MySQL 8可能不支持或与内置驱动程序兼容。

Installing a newer JDBC driver seemed to fix the problem and allow the DSN to verify. 安装较新的JDBC驱动程序似乎可以解决问题,并允许DSN进行验证。

  1. Stop the ColdFusion 2016 Windows Service 停止ColdFusion 2016 Windows服务
  2. Download the latest JDBC driver from https://dev.mysql.com/downloads/connector/j/ . https://dev.mysql.com/downloads/connector/j/下载最新的JDBC驱动程序。 Currently, the latest version is v8.0.11. 目前,最新版本是v8.0.11。
  3. Unzip and copy the new driver jar ( mysql-connector-java-8.0.11.jar ) into directory {cf2016_root}\\wwwroot\\WEB-INF\\lib 将新驱动程序jar( mysql-connector-java-8.0.11.jar )解压缩并复制到目录{cf2016_root}\\wwwroot\\WEB-INF\\lib
  4. Find the old MySQL driver jar and rename it so it doesn't have a .jar extension. 找到旧的 MySQL驱动程序jar并重命名它,使其没有.jar扩展名。 Example, rename mysql-connector-java-5.1.39-bin.jar to mysql-connector-java-5.1.39-bin.jar.old . 例如,将mysql-connector-java-5.1.39-bin.jar重命名为mysql-connector-java-5.1.39-bin.jar.old (The actual location and version number may vary, but it's usually located in {cf2016_root}\\lib\\ ) (实际位置和版本号可能会有所不同,但通常位于{cf2016_root}\\lib\\

  5. Restart the ColdFusion 2016 Windows Service 重新启动ColdFusion 2016 Windows服务

Finally, create a new DSN using Driver Type = Other and enter the following. 最后,使用Driver Type = Other创建一个新DSN并输入以下内容。 Just replace "YourDatasourceName" and "YourDatabaseName" with the correct values. 只需用正确的值替换“YourDatasourceName”和“YourDatabaseName”即可。

  • CF Data Source Name: YourDatasourceName CF数据源名称: YourDatasourceName
  • JDBC URL: jdbc:mysql://127.0.0.1:3306/YourDatabaseName?tinyInt1isBit=false& JDBC URL: jdbc:mysql://127.0.0.1:3306/YourDatabaseName?tinyInt1isBit=false&
  • Driver Class: com.mysql.jdbc.Driver 驱动程序类: com.mysql.jdbc.Driver
  • Driver Name: com.mysql.jdbc.Driver 驱动程序名称: com.mysql.jdbc.Driver
  • User name: root 用户名: root
  • Password : (your password) 密码:( (your password)

Without seeing your real DSN settings, this is just a guess, but... verify the Server setting is correct. 如果没有看到您真正的DSN设置,这只是猜测,但是...验证服务器设置是否正确。 Since MySQL is running on the same machine as CF, enter either localhost or 127.0.0.1 由于MySQL与CF在同一台计算机上运行,​​因此请输入localhost127.0.0.1

服务器名称Localhost

I confirmed that entering an invalid server name like NotARealServerName (no computer by that name on the network) produces the same error you're seeing when you try and verify the DSN in CF11. 我确认输入无效的服务器名称(如NotARealServerName (网络上没有该名称的计算机))会产生您在尝试验证CF11中的DSN时看到的相同错误。

服务器名称无效

验证DSN SQLNonTransientConnectionException

Once you get it working, I'd strongly recommend creating a separate user account , granting the appropriate permissions, and using that with the CF DSN (instead of "root"). 一旦你开始工作,我强烈建议你创建一个单独的用户帐户 ,授予适当的权限,并将其与CF DSN(而不是“root”)一起使用。

Problem was with version mysql connector java . 问题是版本 mysql连接器java
First time I used the latest version Connector/J 8.0.11 and need to use previous version Connector/J 5.1.46 . 我第一次使用最新版本的Connector/J 8.0.11 ,需要使用以前版本的Connector/J 5.1.46 Advice of Ageax's helped me a lot! Ageax的建议给了我很多帮助!
Work it both MySQL 5 and Other drivers. 兼顾MySQL 5Other驱动程序。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM