18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Cassandra CQL・MySQL】コマンドマニュアル

Last updated at Posted at 2015-02-11

1. 言葉の意味

CassandraとMySQLの言葉の対応関係は以下。

Cassandra MySQL
キースペース (keyspace) データベース (database)
カラムファミリ (columnfamily) テーブル (table)

また、cqlshはCQLクライアントであり、cqlshを使うことでCassandraをSQLライクに使うことが出来ます。

  • CQL:Cassandra Query Language
  • SQL:Structured Query Language

2. キースペース作成/削除/選択

▼Cassandra

create keyspace キースペース名;
drop keyspace キースペース名;
use キースペース名;

▼MySQL

create database データベース名;
drop database データベース名;
use データベース名;
  • Cassandra:use キースペース名;;は省略不可
  • MySQL:use データベース名;;は省略可能

3. カラムファミリ作成/削除/確認

▼Cassandra

create columnfamily カラムファミリ名(key名 データ型 PRIMARY KEY, カラム名1 データ型, カラム名2 データ型, ...);
drop columnfamily カラムファミリ名;
describe columnfamily カラムファミリ名;

▼MySQL

create table テーブル名 (カラム名1 データ型, カラム名2 データ型, ...);
drop table テーブル名;
desc テーブル名;
  • 確認コマンドのみ、MySQLの方が簡易

4. データの取得/挿入/更新

▼Cassandra

select カラム名 from カラムファミリ名;
insert into カラムファミリ名 (key名, カラム名1, カラム名2, ...) values (キー値, 値1, 値2, ...);
update カラムファミリ名 set カラム名1 = 値1, カラム名2 = 値2, ... where キー名 = キー値;

▼MySQL

select カラム名 from テーブル名;
insert into テーブル名 (カラム名1, カラム名2, ...) values (値1, 値2, ...);
update テーブル名 set カラム名1 = 値1, カラム名2 = 値2, ... where カラム名 = 値;
  • Cassandra:where文で指定できるカラム名は、「key名」or「インデックス貼ったもの」のみ
  • Cassandraでbetweenは使えない → >=<=を併用してbetweenを作る

※下記、2015/06/21追記※

5. 一覧表示

▼Cassandra

describe keyspaces;
describe tables;
  • describedescと省略可能

▼MySQL

show databases;
show tables;
18
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?