Hello, in this video we'll look at Crash, a command line interface for CrateDB. We'll start by downloading a copy of Crash. Then we'll use it to connect both to a CrateDB cluster in the cloud and one running locally using Docker.
Jumping straight in, we'll start here at the CrateDB website and you're going to want to click 'documentation'. And then down here on the left, there's a Crash CLI section. Inside here, there's various information about what Crash is and how to use it. We're going to want the installation link.
There are two methods for installing Crash. We can either use Python's pip package manager, which is the method that I'm going to use, or you can download it using a curl command and then change the permissions on that and just run it as an executable. But let's go with the Python method and I'll just click copy here, swap to the terminal, and we'll paste a command there and off it goes and installs. Now that installed quite quickly because I have some of these dependencies cached from beforehand. Yours might take a moment while it downloads some of them from the Internet.
So now we've installed Crash, let's connect to our cloud cluster. What we need to do is go over here to the Cloud Console. So this is from when you set up the cluster earlier, and here in the overview, you'll see down the bottom here there's a section connecting to your cluster. Click 'CLI' and what you'll see is the command that we need to invoke Crash and pass it the host names of the hosts, the port of the cluster, and the username that we want to connect. As we have a single node cluster here, so there's only one host name. I'm going to click copy here and then go back to the terminal and paste that command in. I now need to enter the password for the admin user. And with that done, we're connected to our cluster in the cloud.
At the 'CR' prompt here we can type SQL statements. Let's do a simple SELECT ID, hostname from sys.nodes. This is a table that exists already. When we do that, you'll see we have a single entry. There's just one node in our cluster. If we want to look down at the bottom there you'll see the username that I'm connected as 'admin'. The default schema that Crash will use if we don't put a schema name in front of a table name. So that's doc, the cluster that I'm connected to, my course cluster, and the host names that form part of that are sort of over there to the right. If we want to quit Crash, we can do Control+D and return to the terminal prompt. So that covers the cloud cluster.
What we want to do next is connect to a cluster running locally with Docker in case you chose that option. So again, I'll just clear the terminal here. And when we run the cluster on Docker, it runs locally on our machine and it's in a container managed by Docker and it exposes port 4200. So we can just use the default settings in Crash to just type crash and it will connect to that local cluster. So as you saw before, we're now connected, we can type the same SQL statement, SELECT ID, hostname from sys.nodes and you'll see that again we get a single result which is our one node in the cluster. And again down the bottom there we are connected as a user called 'crate'. This time that user doesn't need a password in the Docker environment. And again, our default schema is 'doc' and we have a single host in the cluster, similarly to before. Control+D exits. So that's everything that we need to know about Crash for the moment. So take a moment, download a copy of Crash and get connected to your cluster.