使用Kettle连接 MySQL数据库 ,发生了错误,废话不多说,直接上图:
错误信息:
错误连接数据库 [tcc] :org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database Driver class 'org.gjt.mm.mysql.Driver' could not be found, make surethe 'MySQL' driver (jar file) is installed. org.gjt.mm.mysql.Driver org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database Driver class 'org.gjt.mm.mysql.Driver' could not be found, make surethe 'MySQL' driver (jar file) is installed. org.gjt.mm.mysql.Driver at org.pentaho.di.core.database.Database.normalConnect(Database.Java:428) at org.pentaho.di.core.database.Database.connect(Database.java:358) at org.pentaho.di.core.database.Database.connect(Database.java:311) at org.pentaho.di.core.database.Database.connect(Database.java:301) atorg.pentaho.di.core.database.DatabaseFactory.getConnectionTestReport(DatabaseFactory.java:80) atorg.pentaho.di.core.database.DatabaseMeta.testConnection(DatabaseMeta.java:2686) atorg.pentaho.ui.database.event.DataHandler.testDatabaseConnection(DataHandler.java:546) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) atorg.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:313) atorg.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:157) atorg.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:141) at org.pentaho.ui.xul.swt.tags.SwtButton.access$500(SwtButton.java:43) atorg.pentaho.ui.xul.swt.tags.SwtButton$4.widgetSelected(SwtButton.java:138) at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.eclipse.jface.window.Window.runEventLoop(Window.java:820) at org.eclipse.jface.window.Window.open(Window.java:796) at org.pentaho.ui.xul.swt.tags.SwtDialog.show(SwtDialog.java:389) at org.pentaho.ui.xul.swt.tags.SwtDialog.show(SwtDialog.java:318) atorg.pentaho.di.ui.core.database.dialog.XulDatabaseDialog.open(XulDatabaseDialog.java:116) atorg.pentaho.di.ui.core.database.dialog.DatabaseDialog.open(DatabaseDialog.java:59) atorg.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.newConnection(SpoonDBDelegate.java:464) atorg.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.newConnection(SpoonDBDelegate.java:451) at org.pentaho.di.ui.spoon.Spoon.newConnection(Spoon.java:8728) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) atorg.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:313) atorg.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:157) atorg.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:141) atorg.pentaho.ui.xul.jface.tags.JfaceMenuitem.access$100(JfaceMenuitem.java:43) atorg.pentaho.ui.xul.jface.tags.JfaceMenuitem$1.run(JfaceMenuitem.java:106) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) atorg.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545) atorg.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490) atorg.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.pentaho.di.ui.spoon.Spoon.readAndDispatch(Spoon.java:1319) at org.pentaho.di.ui.spoon.Spoon.waitForDispose(Spoon.java:7939) at org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:9190) at org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:654) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.pentaho测试数据mons.launcher.Launcher.main(Launcher.java:92) Caused by: org.pentaho.di.core.exception.KettleDatabaseException: Driver class 'org.gjt.mm.mysql.Driver' could not be found, make surethe 'MySQL' driver (jar file) is installed. org.gjt.mm.mysql.Driver atorg.pentaho.di.core.database.Database.connectUsingClass(Database.java:522) atorg.pentaho.di.core.database.Database.connectUsingClass(Database.java:4697) atorg.pentaho.di.core.database.Database.normalConnect(Database.java:414) ... 55 more Caused by: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver at java.NET.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.Net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) atorg.pentaho.di.core.database.Database.connectUsingClass(Database.java:497) ... 57 more 主机名 : 210.17.19.79 端口 : 3306 数据库名:test
------------------------------方法1-------------------------
错误信息显示是jar包未安装,有问题找百度:
下载jar包:mysql-connector-java-5.1.15-bin.jar
放到Kettle安装目录下:在/data-integration/lib或者/data-integration/libswt/win64/
重启Spoon.bat
注意下面的方法并不是上面连接数据库失败的解决办法,而是一起其他故障的处理方法。
------------------------------方法2-------------------------
解决办法:该错误由所连数据库中的max_allowed_packet字段引起,查询所连接数据库的该字段将字段大小设置更大问题解决。修改max_allowed_packet字段大小有两种方法,具体如下:
方法1:用语句设置,但是这种情况可能会出现mysql重启后所设置的值失效。
show VARIABLES like'%max_allowed_packet%';
set globalmax_allowed_packet = 1024*1024
2.1方法2:在数据库下my.ini文件中添加如下语句。将max_allowed_packet改为1G.如下图所示。修改完成后,需要重启mysql。
------------------------------方法3-------------------------
解决方法是:
root使用密码123456从任何主机连接到mysql服务器的话。mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANTOPTION; Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
2. 允许用户root从ip为172.16.0.148的主机连接到mysql服务器,并使用123456作为密码
mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANTOPTION; Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
3. 允许用户root从ip为172.16.0.148的主机连接到mysql服务器的dk数据库,并使用123456作为密码
mysql>GRANT ALL PRIVILEGES ON dk.* TO 'root'@'172.16.0.148' IDENTIFIED BY '123456'WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
授权完成后,再一次连接 ------------------------------方法4------------------------- 测试查看下时间
selectnow();
### 1、通过命令修改 设置为 东八区,重启连接之后,查看
set global time_zone = '+8:00'; show variables like '%time_zone%';
 ### 2、修改配置文件 找到my.ini, 在mysqld 下增加 default-time-zone = '+8:00' 必须放到mysqld 下,放入其它位置无效  ------------------------------方法5------------------------- 修改kattle的连接MySQL--选项-增加参数(关于时区的)
useUnicode=true characterEncoding=utf8 useSSL=true serverTimezone=GMT+8
注意下图中的这个参数不要了
zeroDateTimeBehavior=convertToNull

查看更多关于Kettle连接MySQL数据库出现问题的详细内容...