Tutorial

Connecting and creating a database

Connect with the mysql client, see what the server says about itself, and create, use and drop a database.

This tutorial runs on the SQL front-end. Every statement in it was run on raftdb-mysql (for the MySQL dialect or for MariaDB) and on a real MySQL 9.7 or MariaDB 11.4, and the outputs were compared line by line, so what you type here behaves as it does on MySQL, except where the text says the dialects differ.

You need a running front-end: see Starting and stopping. The examples assume the MySQL dialect on port 3307 and the user app.

Connect#

mysql -h 127.0.0.1 -P 3307 -u app -p

For MariaDB use mariadb --skip-ssl -h 127.0.0.1 -P 3308 -u app -p.

Ask the server about itself#

SQL
SELECT VERSION();
SELECT @@version_comment, @@autocommit, @@sql_mode;
SHOW DATABASES;

VERSION() answers 8.0.36-Raft DB in the MySQL dialect and 11.4.13-MariaDB-Raft DB in the MariaDB dialect; @@version_comment says Raft DB. The default sql_mode differs by dialect: the MySQL one contains ONLY_FULL_GROUP_BY, the MariaDB one does not. SHOW DATABASES lists information_schema and the databases made through this front-end.

Create a database#

SQL
CREATE DATABASE shop;
USE shop;
SELECT DATABASE();

USE sets the default database of your session. SELECT DATABASE() answers shop.

A database is a directory on the server, and its name can be anything MySQL allows (spaces and accents too: Raft DB stores such a name encoded). The tutorial starts each time with a clean slate:

SQL
DROP DATABASE IF EXISTS tut3;
CREATE DATABASE tut3;
USE tut3;

Drop a database#

SQL
DROP DATABASE tut3;

DROP DATABASE removes the database and everything in it; there is no undo and no trash folder. The server stops the tables' threads first, then deletes the directory.

What the server says about a mistake#

Errors come with MySQL's numbers and texts:

SQL
USE nosuch;

answers error 1049, Unknown database 'nosuch'. Error 1046, No database selected, is what a statement that needs a database gets when none was chosen.

Next#

Tables, keys and types.