Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change CockroachDB's default database?

When I connect to CockroachDB using cockroach sql, I have to prefix all table names with the name of the database:

SELECT * FROM db.table1;

If I forget to specify the database, like

SELECT * FROM table1;

I get the error pq: table "table1" does not exist.

like image 818
benesch Avatar asked Apr 10 '17 19:04

benesch


People also ask

How do I create a database in CockroachDB?

Once in the CockroachDB SQL shell, you can work with your database like you would any relational database. By default, when the SQL shell launches you’ll be in the defaultdb, so your first step will probably be to create your own database using CREATE DATABASE.

Is CockroachDB better than MySQL or PostgreSQL?

If you run your own benchmarks, or if you try to find existing benchmark results online, be sure that they do not compare apples with oranges: the default configuration of CockroachDB provides better safety and correctness than the default configuration of MySQL and PostgreSQL, but that comes at a slight performance cost.

Where can I learn more about CockroachDB?

Cockroach University is our free online course platform, with lots of courses designed to help you get up and running fast! The Cockroach Labs blog has lots of great content about building, running, and scaling a database with CockroachDB.

How do I apply schema changes using Liquibase with cockroach?

Here’s a quick overview of how to apply schema changes using Liquibase with your Cockroach database. Download the JDBC driver jar file for PostgreSQL and copy it into your liquibase/lib directory.


1 Answers

You can set the database from an active SQL session by running:

SET DATABASE = [database]

You can also specify this when you connect by passing the --database argument to cockroach sql:

cockroach sql --database=[database]

Both of these are set per-session, so you’ll need to use them every time you connect.

If using a connection string, you can specify the database as the path segment of the URL, e.g.:

postgresql://root@localhost:26257/[database]
like image 53
benesch Avatar answered Oct 20 '22 03:10

benesch