cassandra stand-alone deployment

    Cassandra is a distributed nosql, the installation is very simple, here is the windows installation as an example.

    1. Prepare

    jdk1.8 +

    apache-cassandra-3.5

 

    2. Install jdk

    You need to configure an environment variable JAVA_HOME to point to the jdk installation directory. For example: JAVA_HOME=F:\Java8\jdk1.8.0_101

 

    3. Install cassandra

    Unzip the zip archive, and then do nothing, double-click cassandra.bat in the bin directory to start the cassandra database service.

 

    4. Test

    Use the cassandra client connection tool: datastax devcenter to connect to ocalhost:9042.

 

    5. Basic Concepts

    cql: the cassandra query language, very similar to sql. For details, please refer to:

    http://cassandra.apache.org/doc/latest/cql/index.html

    keyspace: Similar to mysql database.

    table: Similar to mysql table.

    Column: Similar to mysql's column.

    Speaking of this, you may have doubts about how nosql feels similar to mysql. It is true. It is similar to mysql. It is estimated that the author of cassandra hopes that users can use it more easily, and hides the real data structure behind it. In fact, the internal data structure of cassandra is not stored in a two-dimensional array like mysql, but the kv pair used by its internal column to store, that is to say, a cell (cell) of cassandra is a map structure, and the specific format is {column=field1,value=value1,timestamp=111122233} This looks like this, I won't explain it too much here, if you are interested in finding information.

 

    6. Get started quickly

    ####create keyspace

--
CREATE KEYSPACE test
WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};

--
USE test;

   ####create table

CREATE TABLE user(
    id int PRIMARY KEY,
    username text,
    password text);
####insert
INSERT INTO user (id, username, password)
VALUES(1, 'cassandra', '123');

####select
SELECT* FROM user;

Note: If you want to use the filter condition, that is, where clause, the fields that need to be filtered meet: either a part of the primary key, or a 
secondary index is added .

####create secondary index.
CREATEINDEX username_index ON user (username);

####where clause
SELECT * FROM user where username = 'cassandra';



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326686376&siteId=291194637