Master CQLSH
The Cassandra Query Language Shell - Your primary interface to Cassandra!
💻 What is CQLSH?
CQLSH = Cassandra Query Language Shell
It's your primary command-line interface for interacting with Cassandra! Think of it like:
- 💾 MySQL: mysql client → Cassandra: cqlsh
- 🐘 PostgreSQL: psql → Cassandra: cqlsh
- 🗄️ MongoDB: mongo shell → Cassandra: cqlsh
✨ What You Can Do with CQLSH
- ✅ Run CQL queries: SELECT, INSERT, UPDATE, DELETE
- ✅ Create schemas: Keyspaces, tables, indexes
- ✅ Import/Export data: COPY commands, CSV files
- ✅ View cluster info: DESCRIBE commands
- ✅ Execute scripts: Run .cql files
- ✅ Configure settings: Consistency levels, paging
🎯 Why Learn CQLSH?
- 📚 Learning: Best way to learn CQL
- 🐛 Debugging: Quick queries to investigate issues
- 🔧 Administration: Schema changes, maintenance
- 📊 Development: Prototype queries, test data
- 🚀 Scripts: Automate tasks with .cql files
🎓 Master cqlsh = Master Cassandra!
⚙️ Installing CQLSH
Multiple ways to get cqlsh!
With Docker
Easiest - Already included!
Standalone (pip)
Install separately
With Cassandra
Included with installation
Verify Installation
Python Version Required
CQLSH needs Python!
- ✅ Python 3.6+ recommended
- ⚠️ Python 2.7 still works but deprecated
- 📦 Pip install handles dependencies automatically
🔌 Connecting to Cassandra
Different connection scenarios!
Local Connection (Default)
Remote Connection
With Authentication
Execute Commands Directly
CQLSH Command Options
💻 Essential CQLSH Commands
Commands you'll use every day!
DESCRIBE - View Schema
USE - Switch Keyspace
HELP - Get Help
SOURCE - Execute Script
CONSISTENCY - Set Level
PAGING - Control Results
TRACING - Debug Queries
EXIT - Close Shell
⚙️ Configuring CQLSH (.cqlshrc)
Customize your cqlsh experience!
Create Config File
Create ~/.cqlshrc (Linux/Mac) or %USERPROFILE%\.cqlshrc (Windows)
Sample Configuration
Useful Config Options
- color: Syntax highlighting (on/off)
- timezone: Display timestamps in your timezone
- float_precision: Decimal places for floats
- consistency: Default consistency level
- username/password: Auto-login credentials
📦 Importing and Exporting Data
Move data in and out of Cassandra!
Export Data to CSV
Import Data from CSV
COPY Command Tips
- ⚠️ Not for large datasets: Use sstableloader for GB+ data
- ⚠️ Performance: Increase CHUNKSIZE for faster imports
- ⚠️ NULL values: Empty fields = NULL by default
- ⚠️ Data types: CSV must match table schema
- ✅ Good for: < 1GB, testing, migrations
🔧 Common Issues & Solutions
Fix problems quickly!
❌ "Connection refused"
Problem: Can't connect to Cassandra
Solutions:
- Check Cassandra is running:
nodetool status - Verify port 9042 is listening:
netstat -an | grep 9042 - Check firewall rules
- Try explicit IP:
cqlsh 127.0.0.1 9042
❌ "Authentication failed"
Problem: Wrong username/password
Solutions:
- Default credentials:
cassandra / cassandra - Check authentication enabled in cassandra.yaml
- Reset password in system_auth.roles table
❌ "command not found: cqlsh"
Problem: CQLSH not in PATH
Solutions:
❌ "No module named 'cassandra'"
Problem: Python driver not installed
Solution:
❌ Slow queries / Timeout
Problem: Query taking too long
Solutions:
- Add LIMIT to queries:
SELECT * FROM users LIMIT 100 - Increase timeout:
cqlsh --request-timeout=60 - Enable paging:
PAGING 100 - Check query uses partition key
💡 Pro Tips & Tricks
Work smarter with cqlsh!
⌨️ Command History
✏️ Tab Completion
Press TAB to auto-complete:
- Keyspace names
- Table names
- Column names
- CQL keywords
📋 Format Output
🔢 Timing Queries
🎨 Color Output
Edit ~/.cqlshrc:
📝 Multi-Line Statements
🔐 Secure Password Storage
Never put passwords in scripts!
Responsive Ad