Summary: in this tutorial, you will learn how to create a database in the MariaDB server for practicing with JDBC.
A quick introduction to the MariaDB database server
MariaDB is an open-source relational database management system. It is a fork of MySQL. MariaDB retains compatibility with MySQL while providing additional enhancements and features.
MariaDB is a popular choice for serving modern web applications and enterprise databases. We’ll use the MariaDB database server to illustrate how to work
Connecting to the MariaDB server
First, open the terminal on a Unix-like system or command prompt on Windows.
Second, connect to the local MariaDB server using the mysql program:
mysql -u root -p
Code language: SQL (Structured Query Language) (sql)
It’ll prompt you for the password of the root user. Enter a valid password to connect to the MariaDB
server.
Creating a new MariaDB database
First, execute a CREATE
DATABASE
statement to create a database:
create database sales;
Code language: SQL (Structured Query Language) (sql)
It’ll create a new database in the MariaDB server.
Second, show all the databases on the current server:
show databases;
Code language: SQL (Structured Query Language) (sql)
Output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sales |
| sys |
+--------------------+
6 rows in set (0.00 sec)
Code language: SQL (Structured Query Language) (sql)
Creating a new user
First, create a new user named bob
with a password:
CREATE USER 'bob'@'localhost'
IDENTIFIED BY 'P@$$w0rd1';
Code language: SQL (Structured Query Language) (sql)
Please change the username and password to your preferred ones.
Second, grant all privileges (such as SELECT
, INSERT
, UPDATE
, DELETE
, etc.) on all tables within the sales
database to the user bob
:
GRANT ALL PRIVILEGES ON sales.*
TO 'bob'@'localhost';
Code language: SQL (Structured Query Language) (sql)
Third, flush privileges to apply the changes immediately:
FLUSH PRIVILEGES;
Code language: SQL (Structured Query Language) (sql)
Finally, quit the mysql
program:
quit
Code language: SQL (Structured Query Language) (sql)
Summary
- Use the
CREATE DATABASE
statement to create a new database in the MariaDB server. - Use the
CREATE USER
andGRANT
statements to create a user and grant all privileges of the new database to the new user.