General Operation
View Server Status
status
View hbase version
version
DDL operations
Create a table
create ‘member‘,‘member_id‘,‘address‘,‘info‘
Three columns are created: member_id, address, and info.
Knowledge Point Review:Cf is a part of the schema, while column is not.
View table information
describe ‘member‘
DESCRIPTION ENABLED ‘member‘, {NAME => ‘address‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTE true R => ‘ROW‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘ NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘tru e‘}, {NAME => ‘info‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘RO W‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, M IN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}, {NA ME => ‘member_id‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_ VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BL OCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘} 1 row(s) in 0.1800 seconds
Query all tables
list
Delete A columnfamily
The member_id column family is redundant because it is the primary key, so we need to delete it.
alter ‘member‘,‘delete‘=>‘member_id‘
Drop table
To test the drop operation, create a table first.
create ‘tmp_table‘,‘info‘
Before deleting a table, you must disable the table before dropping it.
disable ‘tmp_table‘drop ‘tmp_table‘
Determine whether the table is enable
is_enabled ‘member‘
Determine whether the table is disabled
is_disabled ‘member‘
DML operations
Insert record
Format:Put table name row_key Cf: column Value
put ‘member‘,‘luogankun‘,‘info:age‘,‘27‘put ‘member‘,‘luogankun‘,‘info:birthday‘,‘1986-09-05‘put ‘member‘,‘luogankun‘,‘info:company‘,‘asinainfo-linkage‘put ‘member‘,‘luogankun‘,‘address:country‘,‘china‘put ‘member‘,‘luogankun‘,‘address:province‘,‘beijing‘put ‘member‘,‘luogankun‘,‘address:city‘,‘beijing‘put ‘member‘,‘spring‘,‘info:age‘,‘27‘put ‘member‘,‘spring‘,‘info:birthday‘,‘1986-05-14‘put ‘member‘,‘spring‘,‘info:company‘,‘asinainfo-linkage‘put ‘member‘,‘spring‘,‘address:country‘,‘china‘put ‘member‘,‘spring‘,‘address:province‘,‘hubei‘put ‘member‘,‘spring‘,‘address:city‘,‘wuhan‘put ‘member‘,‘spring‘,‘info:favorite‘,‘shopping‘
Knowledge Point Review:Column is fully dynamically scalable, and each row can have different columns.
Obtains all data of a rowkey.
Format:Get table name row_key
get ‘member‘,‘luogankun‘COLUMN CELL address:city timestamp=1409122962541, value=beijing address:country timestamp=1409122962468, value=china address:province timestamp=1409122962510, value=beijing info:age timestamp=1409122962328, value=27 info:birthday timestamp=1409122962399, value=1986-09-05 info:company timestamp=1409122962434, value=asinainfo-linkage
Knowledge Point Review:Htable is automatically sorted by rowkey Lexicographic Order (,). Each row contains any number of columns. columns are automatically sorted by columnkey (Address: City, address: country, address: province, Info: age, info: Birthday, Info: Company) Automatic Sorting.
Obtains an ID and all data of a column family.
Format:Get table name row_key Column
get ‘member‘,‘luogankun‘,‘info‘COLUMN CELL info:age timestamp=1409122962328, value=27 info:birthday timestamp=1409122962399, value=1986-09-05 info:company timestamp=1409122962434, value=asinainfo-linkage
Obtains an ID, all data of a column in a column family.
Format:Get table name row_key Cf: Column
get ‘member‘,‘luogankun‘,‘info:age‘COLUMN CELL info:age timestamp=1409122962328, value=27
Update a record
Format:Put table name row_key Cf: column Value
Change luogankun's age to 18
put ‘member‘,‘luogankun‘,‘info:age‘,‘18‘get ‘member‘,‘luogankun‘,‘info:age‘COLUMN CELL info:age timestamp=1409123175384, value=18
Knowledge Point Review:Query returns the latest value by default..
Use timestamp to obtain data of a specified version
Format:Get table name row_key {Column => 'cf: column', timestamp => xxxxxx}
get ‘member‘,‘luogankun‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1409122962328}COLUMN CELL info:age timestamp=1409122962328, value=27 get ‘member‘,‘luogankun‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1409123175384}
COLUMN CELL info:age timestamp=1409123175384, value=18
Knowledge Point Review:Each column can have any number of values, which are automatically sorted by timestamp in reverse order. tablename + rowkey + column + timestamp => Value
Full table Scan
Format:Scan table name
scan ‘member‘ROW COLUMN+CELL luogankun column=address:city, timestamp=1409122962541, value=beijing luogankun column=address:country, timestamp=1409122962468, value=china luogankun column=address:province, timestamp=1409122962510, value=beijing luogankun column=info:age, timestamp=1409123175384, value=18 luogankun column=info:birthday, timestamp=1409122962399, value=1986-09-05 luogankun column=info:company, timestamp=1409122962434, value=asinainfo-linkage spring column=address:city, timestamp=1409122962828, value=wuhan spring column=address:country, timestamp=1409122962754, value=china spring column=address:province, timestamp=1409122962787, value=hubei spring column=info:age, timestamp=1409122962592, value=27 spring column=info:birthday, timestamp=1409122962623, value=1986-05-14 spring column=info:company, timestamp=1409122962670, value=asinainfo-linkage spring column=info:favorite, timestamp=1409122963494, value=shopping
Delete the 'info: age' field of the spring value.
Format:Delete table name row_key Cf: Column
View
get ‘member‘,‘spring‘,‘info:age‘COLUMN CELL info:age timestamp=1409122962592, value=27
Delete again
delete ‘member‘,‘spring‘,‘info:age‘
Check whether the comparison is deleted.
get ‘member‘,‘spring‘,‘info:age‘COLUMN CELL 0 row(s)
Query the number of rows in a table
Format:Count table name
count ‘member‘
Delete the entire row
Format:Deleteall table name row_key
deleteall ‘member‘,‘spring‘
Clear the entire table
Format: truncate table name
truncate ‘member‘Truncating ‘member‘ table (it may take a while): - Disabling table... - Dropping table... - Creating table...
We can see that hbase first disable the table, then drop it, and then recreate the table to implement the truncate function.
Common hbase shell operations based on hbase