1.1 安装包准备
[root@hadoop102 桌面]# rpm -qa|grep mysql
mysql-libs-5.1.73-7.el6.x86_64
[root@hadoop102 桌面]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
[root@hadoop102 software]# unzip mysql-libs.zip [root@hadoop102 software]# ls mysql-libs.zip mysql-libs
[root@hadoop102 mysql-libs]# ll 总用量 76048 -rw-r--r--. 1 root root 18509960 3 月 26 2015 MySQL-client-5.6.24-1.el6.x86_64.rpm -rw-r--r--. 1 root root 3575135 12 月 1 2013 mysql-connector-java-5.1.27.tar.gz -rw-r--r--. 1 root root 55782196 3 月 26 2015 MySQL-server-5.6.24-1.el6.x86_64.rpm
1.2安装 MySql 服务器
[root@hadoop102 mysql-libs]# rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm
[root@hadoop102 mysql-libs]# cat /root/.mysql_secret
OEXaQuS8IWkG19Xs
[root@hadoop102 mysql-libs]# service mysql status
[root@hadoop102 mysql-libs]# service mysql start
1.3 安装 MySql 客户端
[root@hadoop102 mysql-libs]# rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm
[root@hadoop102 mysql-libs]# mysql -uroot -pOEXaQuS8IWkG19Xs
mysql>SET PASSWORD=PASSWORD(‘000000‘);
mysql>exit
1.4 MySql 中 user 表中主机配置
[root@hadoop102 mysql-libs]# mysql -uroot -p000000
mysql>show databases;
mysql>use mysql;
mysql>show tables;
mysql>desc user;
mysql>select User, Host, Password from user;
mysql>update user set host=‘%‘ where host=‘localhost‘;
mysql>delete from user where Host=‘hadoop102‘; mysql>delete from user where Host=‘127.0.0.1‘; mysql>delete from user where Host=‘::1‘;
mysql>flush privileges;
mysql>quit;
2.1 驱动拷贝
[root@hadoop102 mysql-libs]# tar -zxvf mysql-connector-java-5.1.27.tar.gz
[root@hadoop102 mysql-connector-java-5.1.27]# cp mysql-connector-java-5.1.27-bin.jar
/opt/module/hive/lib/
2.2 配置 Metastore 到 MySql
[atguigu@hadoop102 conf]$ touch hive-site.xml
[atguigu@hadoop102 conf]$ vi hive-site.xml
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://hadoop102:3306/metastore?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>000000</value> <description>password to use against metastore database</description> </property> </configuration>
[atguigu@hadoop102 mysql-libs]$ mysql -uroot -p000000
[atguigu@hadoop102 hive]$ bin/hive
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| metastore |
| mysql |
| performance_schema |
| test |
+--------------------+
3.1 启动 hiveserver2 服务
[atguigu@hadoop102 hive]$ bin/hiveserver2
3.2 启动 beeline
[atguigu@hadoop102 hive]$ bin/beeline Beeline version 1.2.1 by Apache Hive beeline>
3.3 连接 hiveserver2
beeline> !connect jdbc:hive2://hadoop102:10000(回车) Connecting to jdbc:hive2://hadoop102:10000 Enter username for jdbc:hive2://hadoop102:10000: atguigu(回车) Enter password for jdbc:hive2://hadoop102:10000: (直接回车) Connected to: Apache Hive (version 1.2.1) Driver: Hive JDBC (version 1.2.1) Transaction isolation: TRANSACTION_REPEATABLE_READ 0: jdbc:hive2://hadoop102:10000> show databases; +----------------+--+ | database_name | +----------------+--+ | default | | hive_db2 | +----------------+--+
[atguigu@hadoop102 hive]$ bin/hive -help usage: hive -d,--define <key=value> Variable subsitution to apply to hive commands. e.g. -d A=B or --define A=B --database <databasename> Specify the database to use -e <quoted-query-string> SQL from command line -f <filename> SQL from files -H,--help Print help information --hiveconf <property=value> Use value for given property --hivevar <key=value> Variable subsitution to apply to hive commands. e.g. --hivevar A=B -i <filename> Initialization SQL file -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
[atguigu@hadoop102 hive]$ bin/hive -e "select id from student;"
[atguigu@hadoop102 datas]$ touch hivef.sql
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql
[atguigu@hadoop102 hive]$ bin/hive -f /opt/module/datas/hivef.sql > /opt/module/datas/hive_result.txt
hive(default)>exit; hive(default)>quit;
hive(default)>dfs -ls /;
hive(default)>! ls /opt/module/datas;
[atguigu@hadoop102 ~]$ cat .hivehistory
<property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> <description>location of default database for the warehouse</description> </property>
<property> <name>hive.cli.print.header</name> <value>true</value> </property> <property> <name>hive.cli.print.current.db</name> <value>true</value> </property>
[atguigu@hadoop102 conf]$ pwd /opt/module/hive/conf [atguigu@hadoop102 conf]$ mv hive-log4j.properties.template hivelog4j.properties
hive>set;
[atguigu@hadoop103 hive]$ bin/hive -hiveconf mapred.reduce.tasks=10;
hive (default)> set mapred.reduce.tasks;
hive (default)> set mapred.reduce.tasks=100;
hive (default)> set mapred.reduce.tasks;
原文:https://www.cnblogs.com/qiu-hua/p/13360833.html