How to move a Hive table from one database to another? - Big Data In Real World

How to move a Hive table from one database to another?

What is an efficient way to check if a Spark DataFrame is empty?
December 29, 2021
What is the difference between static partitioning and dynamic partitioning in Hive?
January 12, 2022
What is an efficient way to check if a Spark DataFrame is empty?
December 29, 2021
What is the difference between static partitioning and dynamic partitioning in Hive?
January 12, 2022

Let’s see how to move a Hive table from one database to another in action.

We are currently inside a database named hirw. Let’s list the table under hirw.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables;

+-----------+--+
| tab_name  |
+-----------+--+
| employee  |
+-----------+--+

We got one table named employee under database hirw. Let’s create a new database named hirw_2

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> create database hirw_2;

No rows affected (0.275 seconds)

Move table from hirw database to hirw_2 database

Hive offers a convenient alter table..rename command to move a Hive table from one database to another.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> alter table employee rename to hirw_2.employee;

No rows affected (0.649 seconds)

We don’t see the employee table anymore when we now list the tables under hirw.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables;

+-----------+--+
| tab_name  |
+-----------+--+

+-----------+--+

No rows selected (0.287 seconds)

Let’s switch to hirw_2 database and list the tables again. There you go, employee table is under hirw_2 which is exactly what we wanted.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> use hirw_2

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables;

+-----------+--+
| tab_name  |
+-----------+--+
| employee  |
+-----------+--+

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

How to move a Hive table from one database to another?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X