你如何用Java连接到MySQL数据库?
当我尝试时,我明白了
java.sql.SQLException: No suitable driver found for jdbc:mysql://database/table
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
Run Code Online (Sandbox Code Playgroud)
要么
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)
要么
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
Run Code Online (Sandbox Code Playgroud) 我为我的Mac安装了mySQL.除了使用系统首选项中安装的mySQL.prefPane工具启动SQL服务器之外,我想知道从命令行启动的指令.我这样做:
后
苏根
我通过命令行启动mySQL服务器,它产生如下错误:
sh-3.2#/usr/local/mysql/bin/mysqld
111028 16:57:43 [警告]设置lower_case_table_names = 2,因为/usr/local/mysql-5.5.17-osx10.6-x86_64/data/的文件系统不区分大小写
111028 16:57:43 [ERROR]致命错误:请阅读本手册的"安全性"部分,了解如何以root身份运行mysqld!
111028 16:57:43 [错误]中止
111028 16:57:43 [注意]/usr/local/mysql/bin/mysqld:关闭完成
请帮我!
编辑:
原因在于:http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html
下面的xdazz答案中描述了一个解决方案.
当我在maven test本地运行时通过.但是当我在CI服务器上运行它时出现此错误.
Error Message
Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
Stacktrace
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.net.UnknownHostException: mysql …Run Code Online (Sandbox Code Playgroud)