Initialization failure of hiveMetastore metadata base: java.io.IOException: Schema script failed, errorcode 2

Keywords: Big Data hive Apache MySQL Java

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 259, in <module>
    HiveMetastore().execute()
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 280, in execute
    method(env)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 59, in start
    self.configure(env)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive_metastore.py", line 73, in configure
    hive(name = 'metastore')
  File "/usr/lib/python2.6/site-packages/ambari_commons/os_family_impl.py", line 89, in thunk
    return fn(*args, **kwargs)
  File "/var/lib/ambari-agent/cache/common-services/HIVE/0.12.0.2.0/package/scripts/hive.py", line 320, in hive
    user = params.hive_user
  File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 155, in __init__
    self.env.run()
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 160, in run
    self.run_action(resource, action)
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 124, in run_action
    provider_action()
  File "/usr/lib/python2.6/site-packages/resource_management/core/providers/system.py", line 273, in action_run
    tries=self.resource.tries, try_sleep=self.resource.try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 71, in inner
    result = function(command, **kwargs)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 93, in checked_call
    tries=tries, try_sleep=try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 141, in _call_wrapper
    result = _call(command, **kwargs_copy)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 294, in _call
    raise Fail(err_msg)
resource_management.core.exceptions.Fail: Execution of 'export HIVE_CONF_DIR=/usr/hdp/current/hive-metastore/conf/conf.server ; /usr/hdp/current/hive-metastore/bin/schematool -initSchema -dbType mysql -userName hive -passWord [PROTECTED] -verbose' returned 1. WARNING: Use "yarn jar" to launch YARN applications.
Metastore connection URL:	 jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver :	 org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:	 hive
Starting metastore schema initialization to 1.2.1000
Initialization script hive-schema-1.2.1000.mysql.sql
Connecting to jdbc:derby:;databaseName=metastore_db;create=true
Connected to: Apache Derby (version 10.10.2.0 - (1582446))
Driver: Apache Derby Embedded JDBC Driver (version 10.10.2.0 - (1582446))
Transaction isolation: TRANSACTION_READ_COMMITTED
0: jdbc:derby:> !autocommit on
Autocommit status: true
0: jdbc:derby:> /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ 
Error: Syntax error: Encountered "<EOF>" at line 1, column 64. (state=42X01,code=30000)

Closing: 0: jdbc:derby:;databaseName=metastore_db;create=true
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
	at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:285)
	at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:258)
	at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:508)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: Schema script failed, errorcode 2
	at org.apache.hive.beeline.HiveSchemaTool.runBeeLine(HiveSchemaTool.java:391)
	at org.apache.hive.beeline.HiveSchemaTool.runBeeLine(HiveSchemaTool.java:348)
	at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:281)
	... 8 more
*** schemaTool failed ***

The analysis error can be seen because the SQL report syntax error in the SQL script hive-schema-1.2.1000.mysql.sql is executed. At first, I thought it was because the version of the SQL script did not match the version of the MySQL database we used, resulting in hive-schema-1.2.1000.mysql.sql/*!40101... This initial SQL statement is deleted, hiveMetastore is restarted, and SQL grammar errors are still reported. At this point, the reason for the MySQL version can be ruled out.

Continue reading the error log:
The error was triggered by executing the instruction / usr/hdp/current/hive-metastore/bin/schematool -initSchema -dbType mysql -userName hive -passWord [PROTECTED] -verbose. Look at the following printed log:

Metastore connection URL:	 jdbc:derby:;databaseName=metastore_db;create=true
Metastore Connection Driver :	 org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:	 hive


It is found that the database Name used to connect the Metadatabase is not the hive we passed in, but the metastore_db.
Driver is not a mysql driver, but a local Derby database driver, org. apache. derby. jdbc. Embedded Driver.

It shows that although we call the schematool instruction to pass in the data type is MySQL and the name of the database is mysql, the actual call is a derby database, so we always pack sql syntax errors because the sql script file of MySQL is executed on the Derby database.

The first thought is that our configuration file hive-site.xml has problems. Check that the configuration is correct. The configuration of metastore is mysql.

It was later found that there was another hive-site.xml under / etc/haddoop/conf. Sure enough, the configuration file did not have any configuration items about matastroe. Copy / etc/hive/conf/hive-site.xml to replace the file and solve the problem.

PS:derby database is the default hiveMetaStore database type. If we do not specify using other databases such as mysql or oracle, we use derby database by default.

Therefore, it can be analyzed that when initializing the hiveMetaStore database, the instruction / usr / HDP / current / hive - Metastore / bin / schematool - initSchema - dbType MySQL - userName hive - passWord [PROTECTED] - verbox uses / etc/hive/conf/hive-site.xml, but when submitting to yarn to execute the instruction, it reads / etc / hadp / conf / doove - site. XML again. Item.

Posted by aceconcepts on Thu, 31 Jan 2019 16:00:15 -0800