Cassandra
Cassandra is NoSQL, and original is provided by Facebook.
It is to handle huge data for application use.
Why Cassandra?
Our company provides Web Application which uses MySQL(lack of connections)
Users are increasing and difficult to support only single master <-> slave structure.
We want to switch scalable data sources to resolve this situation.
Of course, there are several solutions in MySQL
- Sharding by code
- Clustrix
- Scale up
Scale up is not exact solution. First 2 are kind of distribution techniques. Finally MySQL solution is not easy to do it, and Cassandra is suitable for our case, so we decided to use cassandra.
The good thing of cassandra is scalable. Add more servers, and can support more traffic from users.
Test on local machine
I use Mac mini for Test
- Download Cassandra binary on local machine
- Single Node
Install Cassandra
In this time, I just download binary from Cassandra website and decompress
Not install
Start cassandra
Go to cassandra directly and go bin directly
./cassandra -f
-f is foreground mode. Without -f, cassandra runs as daemon. (Cannot stop from command) If you can stop cassandra, just Ctrl+C
Cassandra uses 9042 and 7199 port.
cqlsh
cqlsh is simple Cassandra client. Use this and can connect cassandra
./cqlsh
Now, you can enter CQL Shell
Let’s try
In this time, I tried
- Create Keyspace
- Create table under keyspace
- Insert data
- Select data
It’s like MySQL.
MySQL | Cassandra |
Database | Keyspace |
Table | Table |
The keyspace is database of MySQL.
Create Keyspace
CREATE KEYSPACE test WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};
Move test keyspace
Use test;
Create table
CREATE TABLE users ( id int PRIMARY KEY, name text );
Insert record
INSERT INTO users (id, name) VALUES (1, 'Bob');
Retrieve data
SELECT * FROM users;
Other commands
Show all keyspaces
DESCRIBE KEYSPACES;
Show all tables
DESCRIBE TABLES;
Show specific table details
DESCRIBE TABLE users;
コメント