Welcome 微信登录

首页 / 数据库 / MySQL / PHP连接Hive执行sql查询

使用php连接hive的条件1  需要安装thrift  安装步骤#  ./configure --without-ruby #   make && make install如果没有安装libevent libevent-devel的应该先安装这两个依赖库yum -y install libevent libevent-devel安装好后启动hive thrift# ./hive --service hiveserver >/dev/null 2>/dev/null &查看hiveserver默认端口是否打开10000   如果打开表示成功注:php版本要求是5.2或者以上php连接hive代码
  1. <?  
  2.   
  3. // php连接hive thrift依赖包路径   
  4.  $GLOBALS["THRIFT_ROOT"] = "/var/www/html/hivephp/thrift/";  
  5. // load the required files for connecting to Hive   
  6. require_once $GLOBALS["THRIFT_ROOT"] . "packages/hive_service/ThriftHive.php";  
  7. require_once $GLOBALS["THRIFT_ROOT"] . "transport/TSocket.php";  
  8. require_once $GLOBALS["THRIFT_ROOT"] . "protocol/TBinaryProtocol.php";  
  9. // Set up the transport/protocol/client   
  10. $transport = new TSocket("localhost", 10000);  
  11. $protocol = new TBinaryProtocol($transport);  
  12. $client = new ThriftHiveClient($protocol);  
  13. $transport->open();  
  14.   
  15. // run queries, metadata calls etc   
  16.   
  17. $client->execute("add jar /usr/local/Hadoop/hive/lib/hive-contrib-0.7.0-cdh3u0.jar");  
  18. $client->execute("select count(1) from apilog");  
  19. var_dump($client->fetchAll());  
  20. $transport->close();  
  21.   
  22. ?>  
将以上代码存为test.php到apache的www路径/var/www/html/中  php连接hive的依赖包放到/var/www/html/hivephp/thrift/php连接hive thrift server的lib包,经测试用hive压缩包中自带的php lib无法测试成功 ,php连接hive的lib包下载地址下载地址在Linux公社的1号FTP服务器里,下载地址: FTP地址:ftp://www.linuxidc.com用户名:www.linuxidc.com密码:www.muu.cc在 2011年LinuxIDC.com8月PHP连接Hive执行sql查询下载方法见这里 http://www.linuxidc.net/thread-1187-1-1.html打开浏览器浏览http://localhost/test.php就可以看到查询结果了Hive使用MySQL保存MetastoreHive导入Apache Nginx等日志与分析相关资讯      PHP  Hive 
  • Hive 简明教程 PDF  (今 09:40)
  • Apache Hive v2.1.0-rc1 发布下载  (06月04日)
  • 在 Apache Hive 中轻松生存的12个  (04月07日)
  • Apache Hive v2.1.0 发布下载  (06月22日)
  • SparkSQL读取Hive中的数据  (05月20日)
  • Apache Hive 2.0.0 发布下载,数据  (02月17日)
本文评论 查看全部评论 (0)
表情: 姓名: 字数