How to use the put command to add data in HBase?
In HBase, you can add data using the put command. The steps for adding data using the put command are as follows:
- Access the HBase shell interface and execute the following command:
- HBase command-line interface
- Choose or create a table. If you want to select an existing table, you can use the following command:
- change the name of the table
- To create a new table, you can use the following command:
- Create a table with the name ‘table_name’ and a column family called ‘column_family_name’.
- In this case, table_name refers to the name of the table, and column_family_name refers to the column family of the table.
- Add data using the put command. The syntax of the put command is as follows:
- Insert into the table the specified value at the specified row and column.
- In which, table_name refers to the name of the table, row_key is the primary key of the row, column_family:column_qualifier represents the identifier of the column, and value is the value to be inserted.
- For example, to insert the value value1 into the column1:qualifier1 of the row key row1 in the table table1, you can use the following command:
- Insert ‘value1’ into ‘table1’ at ‘row1’ with qualifier ‘column1:qualifier1’.
- You can use the “put” command as many times as needed to add more data.
- Use the ‘scan’ command to check if the data has been successfully added. The ‘scan’ command is used to scan the data in the table and you can use the following command:
- Please scan the ‘table_name’.
- For example, to scan all the data in table1, you can use the following command:
- scan the ‘table1’
- After executing the scan command, all data in the table will be outputted.
Please ensure that the HBase service is running and the table exists or has been successfully created before executing the put command.