在用hive时遇到这样的一个异常,因为hive的元数据是存储在mysql数据库中,所以对于hive表的操作相应的会操作数据库中表的数据,该问题发生于删除表的时候,创建的时候并未产生该异常。经过查阅资料了解到mysql通过jdbc链接的时候会进行测试’SET OPTION SQL_SELECT_LIMIT=DEFAULT’,但是5.6以后的版本弃用了set的方式。

异常信息

NestedThrowablesStackTrace:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1

异常分析

我用的数据库版本是5.7但是用的驱动版本是5.1.8的,现在5.7的数据库中支持的set语句为:
https://dev.mysql.com/doc/refman/5.7/en/set-statement.html

The SET statement has several forms:

SET var_name = value enables you to assign values to variables that affect the operation of the server or clients. See Section 14.7.4.1, “SET Syntax for Variable Assignment”.

SET CHARACTER SET and SET NAMES assign values to character set and collation variables associated with the current connection to the server. See Section 14.7.4.2, “SET CHARACTER SET Syntax”, and Section 14.7.4.3, “SET NAMES Syntax”.

SET PASSWORD assigns account passwords. See Section 14.7.1.7, “SET PASSWORD Syntax”.

SET TRANSACTION ISOLATION LEVEL sets the isolation level for transaction processing. See Section 14.3.6, “SET TRANSACTION Syntax”.

set option SQL_SELECT_LIMIT…..已经过时。并且在5.6之后该语法就已经被删除了。

5.6相关的set指令
https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_sql_select_limit

然而用的驱动版本较低的情况下,还是使用以前的set指令导致出错。

解决

将驱动版本升级,尽量驱动版本和数据库版本对应,这个问题切换为5.1.22以上即可。

附StackOverflow
http://stackoverflow.com/questions/15669270/option-sql-select-limit-default

Logo

更多推荐