Nifi Unable to Connect to Local MySQL - mysql

I have Mysql running locally on port 3306. Nifi is also set up and working. I have a simple flow between QueryDatabaseTable and SplitAvro as shown,
I have a DBCPConnectionPool controller set up as well,
Database Connection URL: jdbc:mysql://localhost:3306/formulae
Database Driver Class Name: com.mysql.jdbc.Driver
Database Driver Location: C:\Users\chetanyadav\Documents\mysql-connector-java-8.0.12\mysql-connector-java-8.0.12.jar
Database Name - formulae
Table Name - cell_lot
I am trying to access all records in my table using QueryDatabaseTable,
But I get this error,
I am unable to connect to MySQL basically and fetch the data from the tables.
Full Stack Trace of Error:
2018-09-18 09:52:30,917 ERROR [Timer-Driven Process Thread-1] o.a.n.p.standard.QueryDatabaseTable QueryDatabaseTable[id=d5293f61-0165-1000-cd8d-fe9155176abd] Unable to execute SQL select query SELECT * FROM cell_lot due to org.apache.nifi.processor.exception.ProcessException: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.cj.jdbc.Driver' for connect URL 'jdbc:mysql://127.0.0.1:3306/formulae
': org.apache.nifi.processor.exception.ProcessException: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.cj.jdbc.Driver' for connect URL 'jdbc:mysql://127.0.0.1:3306/formulae
'
org.apache.nifi.processor.exception.ProcessException: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.cj.jdbc.Driver' for connect URL 'jdbc:mysql://127.0.0.1:3306/formulae
'
at org.apache.nifi.dbcp.DBCPConnectionPool.getConnection(DBCPConnectionPool.java:276)
at org.apache.nifi.dbcp.DBCPService.getConnection(DBCPService.java:49)
at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.nifi.controller.service.StandardControllerServiceInvocationHandler.invoke(StandardControllerServiceInvocationHandler.java:84)
at com.sun.proxy.$Proxy102.getConnection(Unknown Source)
at org.apache.nifi.processors.standard.QueryDatabaseTable.onTrigger(QueryDatabaseTable.java:303)
at org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1165)
at org.apache.nifi.controller.tasks.ConnectableTask.invoke(ConnectableTask.java:203)
at org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:117)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.cj.jdbc.Driver' for connect URL 'jdbc:mysql://127.0.0.1:3306/formulae
'
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.apache.nifi.dbcp.DBCPConnectionPool.getConnection(DBCPConnectionPool.java:273)
... 17 common frames omitted
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 20 common frames omitted
Any help is greatly appreciated!

I faced the same issue. I was using MySQL-connector.jar, I changed the connector to MySQL-connector-java-5.1.24-bin.jar and it worked. I Think there is a compatibility issue with new versions of the JDBC driver.

Related

Jenkins pipeline throwing CLIENT_PLUGIN_AUTH is required error for mysql connection

I was trying to establish connection to mysql database, using Jenkins pipeline and when do that I get the following error:
com.mysql.cj.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
MySQL db version is 5.1.73
For the same database when I use mysql-connector-java-5.1.39-bin.jar in a Java program I was able to establish connection. But for the version below , higher or the same mysql-connectors I was not able to connect using Jenkins pipeline.
I searched internet and was not able to find a solution. Version compatibility was always mentioned as problem in some posts for this error trace in Java.
Plugins used in Jenkins are database & database-mysql
Here's my pipeline script
import groovy.sql.Sql
node{
Class.forName("com.mysql.jdbc.Driver")
dbConnection = Sql.newInstance("jdbc:mysql://localhost:3306/test", "username", "password","com.mysql.jdbc.Driver")
}

Unable to connect to mysql in AWS

My spring boot application is throwing error when I run the jar in AWS EC2 instance. It works fine when I run in my local system.
My application.properties file is
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/gbi? useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=fa lse&serverTimezone=UTC&autoReconnect=true&failOverReadOnly=false&maxReconne cts=10
spring.jpa.database-platform =org.hibernate.dialect.MySQLDialect
spring.datasource.username=******
spring.datasource.password=******#
spring.datasource.pool.size=20
spring.jpa.hibernate.ddl-auto=update
server.port=8090
When I run the jar in AWS server, I get the following error
Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server. Attempted reconnect 10
times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
followed by,
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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
followed by,
Caused by: java.net.ConnectException: Connection refused (Connection
refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
atjava.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
followed by,
2017-Oct-09 15:24:49.735 WARN [main] o.s.b.a.o.j.DatabaseLookup -
Unable to determine jdbc url from datasource
org.springframework.jdbc.support.MetaDataAccessException: Could not get
Connection for extracting meta data; nested exception is
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get
JDBC Connection; nested exception is
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server. Attempted reconnect 10
times. Giving up.
How to resolve this?
Got to Ec2 and click on Security Groups then in the bottom add a new security group with type as MYSQL/Aurora protocal as TCP and select the port number and then in source select your computer's Ip Address.
You should be able to resolve your issue.
Thanks,
Madhu

spring mvc 3 hibernate exception

I have a problem with the mysql connection, I use JPA / Hibernate 4 with spring mvc 3 / google app engine. I have the error locally or on the google app engine server.
org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [S1000]; error code [0]; Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:651)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy52.findByLogonemailAndPwd(Unknown Source)
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:52)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)
at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at com.sun.proxy.$Proxy64.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1739)
at org.hibernate.loader.Loader.doQuery(Loader.java:828)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
at org.hibernate.loader.Loader.doList(Loader.java:2463)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)
at org.hibernate.loader.Loader.list(Loader.java:2274)
note: Before the application works very well I reboot machine the error is appears.
thank you.
probably you haven't started your mysql server, eg: it's setup as a manual service / executable you have to run first
Maybe you can have a look at your configuration file to see the hostname of mysql server.

How do I access MySQL from CloudBees Jenkins?

I cannot figure out how to access a MySQL database while running in Jenkins CloudBees. I have tried following the Dev#Cloud MySQL, but there are a lot of warnings in the console output and I have to deal with localhost access vs. sockets, which is pretty tricky to debug without a command line.
Is there a way to use the CloudBees MySQL hosting? When I try and use the cloudbees JDBC driver, I get ClassNotFound error messages.
Update: The answer below clarified that I cannot use the CloudBees driver, so I am now using the regular MySQL connector through the c3p0 connection pool. Based on comments below, I have limited the number of connections in the pool to 10.
The exact same configuration and Maven command line works when I run it from my development computer, connecting to the Cloudbees Mysql instance.
Unfortunately, I get this error when trying to connect:
Caused by: com.googlecode.flyway.core.exception.FlywayException: Unable to obtain Jdbc connection from DataSource
at com.googlecode.flyway.core.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:864)
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:591)
at com.assuredlabor.db.DatabaseMigrator.migrate(DatabaseMigrator.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 62 more
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at com.googlecode.flyway.core.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
... 72 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 74 more
Any ideas would be appreciated.
You can't use CloudBees JDBC driver from outside the RUN#Cloud container, but you can use a standard MySQL JDBC driver with your RUN database using the host name and port that you can find on RUN#Cloud web console for your DB resource.

Data Migration from SQL Serever Express 2008 R2 to MySQL 5

I am trying to copy a database from SQL Server 2008 Express to MySQL using the MYSQL Migration Toolkit on Windows and keep getting the following connection error.
Connecting to source database and retrieve schemata names.
Initializing JDBC driver ...
Driver class MS SQL JDBC Driver
Opening connection ...
Connection jdbc:jtds:sqlserver://localhost:1433/ePacro2.0;user=sa;password=xxxxxx;charset=utf-8;domain=
The list of schema names could not be retrieved (error: 0).
ReverseEngineeringMssql.getSchemata :Network error IOException: Connection refused: connect
Details:
net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:372)
net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
com.mysql.grt.modules.ReverseEngineeringGeneric.establishConnection(ReverseEngineeringGeneric.java:141)
com.mysql.grt.modules.ReverseEngineeringMssql.getSchemata(ReverseEngineeringMssql.java:99)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.mysql.grt.Grt.callModuleFunction(Unknown Source)
Would you have any idea why this is failing?
I've also tried to export from SQL express 2008 but it won't let me choos a MySQL ODBC connector for my destination.
Having ODBC driver for MS SQL server database, you could try Data Import tool in dbForge Studio for MySQL.