Yang, Tong 48706b7552 MRS COMP-LTS 320-lts.1 version
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2024-04-12 12:51:10 +00:00

42 lines
13 KiB
HTML

<a name="mrs_01_24742"></a><a name="mrs_01_24742"></a>
<h1 class="topictitle1">Importing and Exporting Hive Databases</h1>
<div id="body0000001583613705"><div class="section" id="mrs_01_24742__section31431195464"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_24742__p191431592468">In big data application scenarios, Hive databases and all tables in these databases are usually migrated to another cluster. You can run the Hive database <strong id="mrs_01_24742__b742919516368">export</strong> and <strong id="mrs_01_24742__b040145420364">import</strong> commands to migrate a complete database.</p>
<div class="note" id="mrs_01_24742__note95434624913"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_24742__p15705425017">This section applies to MRS 3.2.0 or later.</p>
<p id="mrs_01_24742__p1645085614240">The Hive database import and export function does not support importing or exporting encrypted tables, transaction tables, HBase external tables, Hudi tables, view tables, and materialized view tables.</p>
</div></div>
</div>
<div class="section" id="mrs_01_24742__section16278135019532"><h4 class="sectiontitle">Prerequisites</h4><ul id="mrs_01_24742__ul104783116711"><li id="mrs_01_24742__li12981441131015">If Hive databases are imported or exported across clusters and Kerberos authentication is enabled for both the source and destination clusters, configure cross-cluster mutual trust.</li><li id="mrs_01_24742__li13244162814167">If you want to run the <strong id="mrs_01_24742__b21321449409">dump</strong> or <strong id="mrs_01_24742__b1013918484017">load</strong> command to import or export databases created by other users, grant the corresponding database permission to the users.<ul id="mrs_01_24742__ul796272916161"><li id="mrs_01_24742__li19318103771612">If Ranger authentication is not enabled for the cluster, log in to FusionInsight Manager to grant the administrator rights of the role to which the user belongs. For details, see section <a href="mrs_01_0949.html">Creating a Hive Role</a>.</li><li id="mrs_01_24742__li1868128141818">If Ranger authentication is enabled for the cluster, grant users the permission to dump and load databases. For details, see <a href="mrs_01_1858.html">Adding a Ranger Access Permission Policy for Hive</a>.</li></ul>
</li><li id="mrs_01_24742__li140114381135">Enable the inter-cluster copy function in the source cluster and destination cluster.</li><li id="mrs_01_24742__li7409153818320">Configure the HDFS service address parameter for the source cluster to access the destination cluster.<p id="mrs_01_24742__p1140993818319"><a name="mrs_01_24742__li7409153818320"></a><a name="li7409153818320"></a>Log in to FusionInsight Manager of the source cluster, click <strong id="mrs_01_24742__b34068924315">Cluster</strong>, choose <strong id="mrs_01_24742__b1412169164315">Services</strong> &gt; <strong id="mrs_01_24742__b24135924310">Hive</strong>, and click <strong id="mrs_01_24742__b184132924316">Configuration</strong>. On the displayed page, search for <strong id="mrs_01_24742__b124136910433">hdfs.site.customized.configs</strong>, add custom parameter <strong id="mrs_01_24742__b9414189134311">dfs.namenode.rpc-address.haclusterX</strong>, and set its value to <em id="mrs_01_24742__i19414691432">Service IP address of the active NameNode instance node in the destination cluster</em>:<em id="mrs_01_24742__i154141898436">RPC port</em>. Add custom parameter <strong id="mrs_01_24742__b134141998433">dfs.namenode.rpc-address.haclusterX1</strong> and set its value to <em id="mrs_01_24742__i2041519916438">Service IP address of the standby NameNode instance node in the destination cluster</em>:<em id="mrs_01_24742__i19415189144319">RPC port</em>. The RPC port of NameNode is <strong id="mrs_01_24742__b1841515924317">25000</strong> by default. After saving the configuration, roll-restart the Hive service.</p>
</li></ul>
</div>
<div class="section" id="mrs_01_24742__section134133490311"><h4 class="sectiontitle">Procedure</h4><ol id="mrs_01_24742__ol152831746311"><li id="mrs_01_24742__li1028219462119"><span>Log in to the node where the client is installed in the source cluster as the Hive client installation user.</span></li><li id="mrs_01_24742__li2282114610113"><a name="mrs_01_24742__li2282114610113"></a><a name="li2282114610113"></a><span>Run the following command to switch to the client installation directory, for example, <strong id="mrs_01_24742__b976907122219"><span id="mrs_01_24742__ph187691078229">/opt/client</span></strong>:</span><p><p id="mrs_01_24742__p12821246418"><strong id="mrs_01_24742__b72821346612">cd <span id="mrs_01_24742__ph4420174711419">/opt/client</span></strong></p>
</p></li><li id="mrs_01_24742__li1728211461814"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_24742__p142824461814"><strong id="mrs_01_24742__b2282246517">source bigdata_env</strong></p>
</p></li><li id="mrs_01_24742__li610182915598"><span>If Kerberos authentication is enabled for the cluster, run the following command to authenticate the user. Otherwise, skip this step.</span><p><p id="mrs_01_24742__p10378152213593"><strong id="mrs_01_24742__b894516174413">kinit</strong> <i><span class="varname" id="mrs_01_24742__varname1994616618443">Hive service user</span></i></p>
</p></li><li id="mrs_01_24742__li9282204611111"><a name="mrs_01_24742__li9282204611111"></a><a name="li9282204611111"></a><span>Run the following command to log in to the Hive client:</span><p><p id="mrs_01_24742__p17282446119"><strong id="mrs_01_24742__b18282946117">beeline</strong></p>
</p></li><li id="mrs_01_24742__li14282246214"><span>Run the following command to create the <strong id="mrs_01_24742__b117402694414">dump_db</strong> database:</span><p><p id="mrs_01_24742__p13282546214"><strong id="mrs_01_24742__b10803135015324">create database </strong><em id="mrs_01_24742__i16394851103219">dump_db</em><strong id="mrs_01_24742__b180310503325">;</strong></p>
</p></li><li id="mrs_01_24742__li192821846716"><span>Run the following command to switch to the <strong id="mrs_01_24742__b199281355154415">dump_db</strong> database:</span><p><p id="mrs_01_24742__p102820461912"><strong id="mrs_01_24742__b133211569339">use </strong><em id="mrs_01_24742__i166891856203311">dump_db</em><strong id="mrs_01_24742__b733145618333">;</strong></p>
</p></li><li id="mrs_01_24742__li152821346417"><span>Run the following command to create the <strong id="mrs_01_24742__b4679117154517">test</strong> table in the <strong id="mrs_01_24742__b10226415134512">dump_db</strong> database:</span><p><p id="mrs_01_24742__p13282194619119"><strong id="mrs_01_24742__b02652382347">create table </strong><em id="mrs_01_24742__i5881103816344">test</em><strong id="mrs_01_24742__b124682423345">(</strong><em id="mrs_01_24742__i15223174363414">id int</em><strong id="mrs_01_24742__b19468104217344">)</strong><strong id="mrs_01_24742__b32820461414">;</strong></p>
</p></li><li id="mrs_01_24742__li528318462116"><span>Run the following command to insert data to the <strong id="mrs_01_24742__b19939173114520">test</strong> table:</span><p><p id="mrs_01_24742__p1128215467110"><strong id="mrs_01_24742__b510681883511">insert into </strong><em id="mrs_01_24742__i12745101819351">test</em><strong id="mrs_01_24742__b12303202211355"> values(</strong><em id="mrs_01_24742__i289582283512">123</em><strong id="mrs_01_24742__b5303172243513">);</strong></p>
</p></li><li id="mrs_01_24742__li1637032672512"><span>Run the following command to set the <strong id="mrs_01_24742__b5171124818455">dump_db</strong> database as the source of the replication policy:</span><p><p id="mrs_01_24742__p43701826162512"><strong id="mrs_01_24742__b157821615174217">alter database</strong> <em id="mrs_01_24742__i1336535174814">dump_db</em> <strong id="mrs_01_24742__b18512726104217">set dbproperties</strong><strong id="mrs_01_24742__b74111731164817"> (</strong><strong id="mrs_01_24742__b19731715482">'</strong><em id="mrs_01_24742__i129331112124812">repl.source.for</em><strong id="mrs_01_24742__b1789619206482">'='</strong>replpolicy1<strong id="mrs_01_24742__b2908326134817">');</strong></p>
<div class="note" id="mrs_01_24742__note1231862445111"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_24742__ul753895155417"><li id="mrs_01_24742__li111289138913">Perform the following steps to set permissions for users when the <strong id="mrs_01_24742__b9191147174916">alter</strong> command is used to modify database attributes:<ul id="mrs_01_24742__ul177021416391"><li id="mrs_01_24742__li1953845125413">If Ranger authentication is not enabled for the cluster, log in to FusionInsight Manager to grant the administrator rights of the role to which the user belongs. For details, see section <a href="mrs_01_0949.html">Creating a Hive Role</a>.</li><li id="mrs_01_24742__li135383535417">If Ranger authentication is enabled for the cluster, grant users the permission to dump and load databases. For details, see <a href="mrs_01_1858.html">Adding a Ranger Access Permission Policy for Hive</a>.</li></ul>
</li><li id="mrs_01_24742__li10514134284212">Databases with replication policy sources configured can be deleted only after their replication policy sources are set to null. To do so, run the following command:<p id="mrs_01_24742__p97864018261"><a name="mrs_01_24742__li10514134284212"></a><a name="li10514134284212"></a><strong id="mrs_01_24742__b18786100182617">alter database</strong> <em id="mrs_01_24742__i147860022617">dump_db</em> <strong id="mrs_01_24742__b8786130112612">set dbproperties</strong><strong id="mrs_01_24742__b87861304263"> (</strong><strong id="mrs_01_24742__b07865018266">'</strong><em id="mrs_01_24742__i378710020266">repl.source.for</em><strong id="mrs_01_24742__b17871002260">'='</strong><strong id="mrs_01_24742__b137871606261">');</strong></p>
</li></ul>
</div></div>
</p></li><li id="mrs_01_24742__li182831461817"><span>Run the following command to export the <strong id="mrs_01_24742__b19557113935114">dump_db</strong> database to the <strong id="mrs_01_24742__b16826194819513">/user/hive/test</strong> directory of the destination cluster:</span><p><p id="mrs_01_24742__p1428374613119"><strong id="mrs_01_24742__b75991840173619">repl dump </strong><em id="mrs_01_24742__i2059215586361">dump_db</em><strong id="mrs_01_24742__b104691416913"> with ('hive.repl.rootdir'='hdfs://hacluster</strong><em id="mrs_01_24742__i19421191269">X</em><em id="mrs_01_24742__i166541416361">/user/hive/test</em><strong id="mrs_01_24742__b134691141292">');</strong></p>
<div class="note" id="mrs_01_24742__note471073434720"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_24742__ul198396177"><li id="mrs_01_24742__li1798311611712"><strong id="mrs_01_24742__b7259252521">hacluster <em id="mrs_01_24742__i82537535219">X</em></strong> is the value of <strong id="mrs_01_24742__b5260165115210">haclusterX</strong> in new custom parameter<strong id="mrs_01_24742__b11261458523">dfs.namenode.rpc-address.haclusterX</strong>.</li><li id="mrs_01_24742__li179831361975">Ensure that the current user has the read and write permissions on the export directory to be specified.</li></ul>
</div></div>
</p></li><li id="mrs_01_24742__li11692440141313"><span>Log in to the node where the client is installed in the destination cluster as the Hive client installation user, and perform <a href="#mrs_01_24742__li2282114610113">2</a> to <a href="#mrs_01_24742__li9282204611111">5</a>.</span></li><li id="mrs_01_24742__li2283114610119"><span>Run the following command to import data from the <strong id="mrs_01_24742__b159891416135720">dump_db</strong> database in the <strong id="mrs_01_24742__b513910223574">/user/hive/test</strong> directory to the <strong id="mrs_01_24742__b192851226135720">load_db</strong> database:</span><p><p id="mrs_01_24742__p5283174612115"><strong id="mrs_01_24742__b4350632103910">repl load </strong><em id="mrs_01_24742__i99708325398">load_db</em><strong id="mrs_01_24742__b135019327395"> from '</strong><em id="mrs_01_24742__i7925175153910">/user/hive/repl</em><strong id="mrs_01_24742__b172354593917">';</strong></p>
<div class="note" id="mrs_01_24742__note1428317468118"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_24742__p16283146114">When the <strong id="mrs_01_24742__b1888114201204">repl load</strong> command is used to import a database, pay attention to the following points when specifying the database name:</p>
<ul id="mrs_01_24742__ul14283246511"><li id="mrs_01_24742__li12831046017">If the specified database does not exist, the database will be created during the import.</li><li id="mrs_01_24742__li1328354615115">If the specified database exists and the value of <strong id="mrs_01_24742__b982916561805">hive.repl.ckpt.key</strong> of the database is the same as the imported path, skip the import operation.</li><li id="mrs_01_24742__li2028311469114">If the specified database already exists and no table or function exists in this database, only the tables in the source database are imported to the current database during the import. Otherwise, the import fails.</li></ul>
</div></div>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24744.html">Data Import and Export in Hive</a></div>
</div>
</div>