Amazon EMR
Developer Guide

Create a Hive Metastore Outside the Cluster

This documentation is for AMI versions 2.x and 3.x of Amazon EMR. For information about Amazon EMR releases 4.0.0 and above, see the Amazon EMR Release Guide. For information about managing the Amazon EMR service in 4.x releases, see the Amazon EMR Management Guide.

Hive records metastore information in a MySQL database that is located, by default, on the master node. The metastore contains a description of the input data, including the partition names and data types, contained in the input files.

When a cluster terminates, all associated cluster nodes shut down. All data stored on a cluster node, including the Hive metastore, is deleted. Information stored elsewhere, such as in your Amazon S3 bucket, persists.

If you have multiple clusters that share common data and update the metastore, you should locate the shared metastore on persistent storage.

To share the metastore between clusters, override the default location of the MySQL database to an external persistent storage location on an Amazon RDS instance.


Hive neither supports nor prevents concurrent write access to metastore tables. If you share metastore information between two clusters, you must ensure that you do not write to the same metastore table concurrently—unless you are writing to different partitions of the same metastore table.

The following procedure shows you how to override the default configuration values for the Hive metastore location and start a cluster using the reconfigured metastore location.

To create a metastore located outside of the cluster

  1. Create a MySQL database.

    Relational Database Service (RDS) provides a cloud-based MySQL database. For information about how to create an Amazon RDS database, see

  2. Modify your security groups to allow JDBC connections between your MySQL database and the ElasticMapReduce-Master security group.

    For information about how to modify your security groups for access, see

  3. Set the JDBC configuration values in hive-site.xml:

    1. Create a hive-site.xml configuration file containing the following information:

          <description>JDBC connect string for a JDBC metastore</description>
          <description>Username to use against metastore database</description>
          <description>Password to use against metastore database</description>

      <hostname> is the DNS address of the Amazon RDS instance running MySQL. <username> and <password> are the credentials for your MySQL database.

      The JDBC drivers are installed by Amazon EMR.


      The value property should not contain any spaces or carriage returns. It should appear all on one line.

    2. Save your hive-site.xml file to a location on Amazon S3, such as s3://mybucket/hive-site.xml.

  4. Create a cluster and specify the Amazon S3 location of the new Hive configuration file.


    To specify the location of the configuration file using the AWS CLI, type the following command, replace myKey with the name of your EC2 key pair, and replace mybucket with your Amazon S3 bucket name.

    • Linux, UNIX, and Mac OS X users:

      aws emr create-cluster --name "Test cluster" --ami-version 3.10 --applications Name=Hue Name=Hive Name=Pig \
      --use-default-roles --ec2-attributes KeyName=myKey \
      --instance-type m3.xlarge --instance-count 3 \
      --bootstrap-actions Name="Install Hive Site Configuration",Path="s3://region.elasticmapreduce/libs/hive/hive-script",\

      Where region is the region where you are launching your cluster.

    • Windows users:

      aws emr create-cluster --name "Test cluster" --ami-version 3.10 --applications Name=Hive Name=Pig --use-default-roles --ec2-attributes KeyName=myKey --instance-type m3.xlarge --instance-count 3 --bootstrap-actions Name="Install Hive Site Configuration",Path="s3://elasticmapreduce/libs/hive/hive-script",Args=["--base-path","s3://region.elasticmapreduce/libs/hive","--install-hive-site","--hive-site=s3://mybucket/hive-site.xml","--hive-versions","latest"]

      Where region is the region where you are launching your cluster.

    The us-east-1 endpoint used above,, should be replaced with the Amazon S3 endpoint for the region in which your cluster will be located.


    For Windows, replace the above Linux line continuation character (\) with the caret (^).

    When you specify the instance count without using the --instance-groups parameter, a single Master node is launched, and the remaining instances are launched as core nodes. All nodes will use the instance type specified in the command.


    If you have not previously created the default EMR service role and EC2 instance profile, type aws emr create-default-roles to create them before typing the create-cluster subcommand.

    For more information on using Amazon EMR commands in the AWS CLI, see

  5. Connect to the master node of your cluster.

    Instructions on how to connect to the master node are available at Connect to the Master Node Using SSH.

  6. Create your Hive tables specifying the location on Amazon S3 by entering a command similar to the following:

    key int,
    value int
    LOCATION s3://mybucket/hdfs/
  7. Add your Hive script to the running cluster.

Your Hive cluster runs using the metastore located in Amazon RDS. Launch all additional Hive clusters that share this metastore by specifying the metastore location.