Kong-Study-Group / dive-in-kong

:book: Dive Into Kong
0 stars 0 forks source link

Cassandra 安装和使用 #13

Open WALL-E opened 7 years ago

WALL-E commented 7 years ago

Installation from RPM packages

  1. Add the Apache repository of Cassandra to /etc/yum.repos.d/cassandra.repo, for example for the latest 3.11 version:

    [cassandra]
    name=Apache Cassandra
    baseurl=https://www.apache.org/dist/cassandra/redhat/311x/
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://www.apache.org/dist/cassandra/KEYS
  2. Install Cassandra, accepting the gpg key import prompts:

    sudo yum install cassandra
  3. Start Cassandra (will not start automatically):

    service cassandra start

download

WALL-E commented 7 years ago

Usage

一:创建keyspace CREATE KEYSPACE demo WITH REPLICATION = {'class':'SimpleStrategy','replication_factor':1};

二:查询有哪些keyspace describe keyspaces;

三:选择keyspace use demo;

四:创建表 cqlsh:demo> CREATE TABLE student(id int, s_name varchar, PRIMARY KEY(id));

五:向表中添加数据 cqlsh:demo> INSERT INTO student (id,s_name) VALUES (1,'Naruto'); cqlsh:demo> INSERT INTO student (id,s_name) VALUES (2,'Naruto');

六:查询数据 cqlsh:demo> select from student; cqlsh:demo> select from student where id=2; cqlsh:demo> select * from student where s_name='Sanji'; 查询没有索引的s_name无法查询.需要先创建一个索引: cqlsh:demo> create index on student(s_name);

七:更新数据 cqlsh:demo> update student set s_name='Luffy' where id=1;

八:删除表数据(必须要有where条件) cqlsh:demo> delete from student where id=2;