Hive installation issues: Hive metastore database is not initialized
After installing hive, if the first thing you did was run hive, hive attempted to create/initialize the metastore_db, but apparently might not get it right. On that initial run, maybe you saw your error:
Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)
Running hive, even though it fails, creates a metastore_db directory in the directory from which you ran hive:
ubuntu15-laptop: ~ $>ls -l |grep metadrwxrwxr-x 5 testuser testuser 4096 Apr 14 12:44 metastore_db
So when you then tried running
ubuntu15-laptop: ~ $>schematool -initSchema -dbType derby
The metastore already existed, but not in complete form.
Soooooo the answer is:
Before you run hive for the first time, run
schematool -initSchema -dbType derby
If you already ran hive and then tried to initSchema and it's failing:
mv metastore_db metastore_db.tmp
Re run
schematool -initSchema -dbType derby
Run hive again
**Also of note: if you change directories, the metastore_db created above won't be found! I'm sure there's a good reason for this that I don't know yet because I'm literally trying to use hive for the first time today. Ahhh here's information on this: metastore_db created wherever I run Hive
I installed hive with HomeBrew(MacOS) at /usr/local/Cellar/hive and afer runningschematool -dbType derby -initSchema
I get the following error message:
Starting metastore schema initialization to 2.0.0Initialization script hive-schema-2.0.0.derby.sqlError: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
However, I can't find either metastore_db or metastore_db.tmp folder under install path, so I tried:
find /usr/ -name hive-schema-2.0.0.derby.sql
vi /usr/local/Cellar/hive/2.0.1/libexec/scripts/metastore/upgrade/derby/hive-schema-2.0.0.derby.sql
- comment the 'NUCLEUS_ASCII' function and 'NUCLEUS_MATCHES' function
- rerun
schematool -dbType derby -initSchema
, then everything goes well!
hope this help someone.
I encountered a similar issue, which I fixed by removing the derby database files rm -Rf $HIVE_HOME/metastore_db
Be aware, this will remove your schema completely!
After cleaning the old schema I could reinitialize with:
$HIVE_HOME/bin/schematool -initSchema -dbType derby
It might differ from where you call hive, try to go to your hive installation directory and run ./bin/hive