HBase的简单应用

运行HBase

$ ssh localhost   #启动ssh
$ cd /usr/local/hadoop
$ ./sbin/start-dfs.sh   #启动Hadoop
$ cd /usr/local/hbase	#切换至/usr/local/hbase,再启动HBase
$ bin/start-hbase.sh	#启动HBase
$ bin/stop-hbase.sh	#进入shell界面
$ exit	#退出HBase
$ bin/stop-hbase.sh	#停止HBase运行

注意:如果在操作HBase的过程中发生错误,可以通过{HBASE_HOME}目录(/usr/local/hbase)下的logs子目录中的日志文件查看错误原因。
这里启动关闭Hadoop和HBase的顺序一定是:
启动Hadoop—>启动HBase—>关闭HBase—>关闭Hadoop

编程实战

HBase中创建表

     $ create 'student','Sname','Ssex','Sage','Sdept','course'
     $ describe 'student'
     $ put 'student','95001','Sname','LiYing'	#当运行命令:put ‘student’,’95001’,’Sname’,’LiYing’时,即为student表添加了学号为95001,名字为LiYing的一行数据,其行键为95001。
     $  put 'student','95001','course:math','80'	#为95001行下的course列族的math列添加了一个数据。
     $ #在HBase中用delete以及deleteall命令进行删除数据操作,它们的区别是:1. delete用于删除一个数据,是put的反向操作;2. deleteall操作用于删除一行数据。
     $ delete 'student','95001','Ssex'
     $ deleteall 'student','95001'
     $ #HBase中有两个用于查看数据的命令:1. get命令,用于查看表的某一行数据;2. scan命令用于查看某个表的全部数据
     $ get 'student','95001'
     $ scan 'student'
     $ #删除表有两步,第一步先让该表不可用,第二步删除表。
     $ disable 'student'
     $ drop 'student'
     

猜你喜欢

转载自blog.csdn.net/February_qing/article/details/88777858