mysql -u "${db_admin_user}" "${db_admin_password_parameter}" -e \
mysql -u "$${db_admin_user}" "$${db_admin_password_parameter}" -e \
"CREATE DATABASE ${metastore_db}; \
"CREATE DATABASE $${metastore_db}; \
GRANT ALL PRIVILEGES ON ${metastore_db}.* TO '${db_hive_user}';"
GRANT ALL PRIVILEGES ON $${metastore_db}.* TO '$${db_hive_user}';"
/usr/lib/hive/bin/schematool -dbType mysql -initSchema \
/usr/lib/hive/bin/schematool -dbType mysql -initSchema \
|| err 'Failed to set mysql schema.'
|| err 'Failed to set mysql schema.'
fi
fi
run_with_retries run_validation
}
function run_validation() {
if ( systemctl is-enabled --quiet hive-metastore ); then
if ( systemctl is-enabled --quiet hive-metastore ); then
# Start metastore back up.
# Start metastore back up.
systemctl restart hive-metastore \
systemctl start hive-metastore \
|| err 'Unable to start hive-metastore service'
|| err 'Unable to start hive-metastore service'
else
else
echo "Service hive-metastore is not loaded"
echo "Service hive-metastore is not loaded"
fi
fi
# Check that metastore schema is compatible.
/usr/lib/hive/bin/schematool -dbType mysql -info || \
err 'Run /usr/lib/hive/bin/schematool -dbType mysql -upgradeSchemaFrom <schema-version> to upgrade the schema. Note that this may break Hive metastores that depend on the old schema'
# Validate it's functioning.
# Validate it's functioning.
if ! timeout 60s beeline -u jdbc:hive2://localhost:10000 -e 'SHOW TABLES;' >& /dev/null; then