[atguigu@hadoop102 software]$ mysql -uroot -p000000
2)新建Hive元数据库
mysql> create database metastore; mysql> quit;
3)初始化Hive元数据库
[atguigu@hadoop102 software]$ schematool -initSchema -dbType mysql -verbose
2.Hive访问
启动hive客户端
[atguigu@hadoop102 hive]$ bin/hive
2)看到如下界面
which: no hbase in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/module/jdk1.8.0_212/bin:/opt/module/hadoop-3.1.3/bin:/opt/module/hadoop-3.1.3/sbin:/opt/module/hive/bin:/home/atguigu/.local/bin:/home/atguigu/bin) Hive Session ID = 36f90830-2d91-469d-8823-9ee62b6d0c26 Logging initialized using configuration in jar:file:/opt/module/hive/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true Hive Session ID = 14f96e4e-7009-4926-bb62-035be9178b02 hive>
3)打印 当前库 和 表头 在hive-site.xml中加入如下两个配置:
hive.cli.print.header true Whether to print the names of the columns in query output.
hive.cli.print.current.db true Whether to include the current database in the Hive prompt.
Connecting to jdbc:hive2://hadoop102:10000 Connected to: Apache Hive (version 3.1.2) Driver: Hive JDBC (version 3.1.2) Transaction isolation: TRANSACTION_REPEATABLE_READ Beeline version 3.1.2 by Apache Hive 0: jdbc:hive2://hadoop102:10000>
Hive常用交互命令
[atguigu@hadoop102 hive]$ bin/hive -help usage: hive -d,--define Variable subsitution to apply to hive commands. e.g. -d A=B or --define A=B --database Specify the database to use -e SQL from command line -f SQL from files -H,--help Print help information --hiveconf
Use value for given property --hivevar Variable subsitution to apply to hive commands. e.g. --hivevar A=B -i Initialization SQL file -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
hive -e
1)“-e”不进入hive的交互窗口执行sql语句
[atguigu@hadoop102 hive]$ bin/hive -e "select id from student;"