MariaDB: Creating a database and user with the Linux terminal

This guide assumes you have installed and setup MariaDB. I will be using version 10.1.40 for this guide.

Login to the SQL server

sudo mysql -u root

Add a new database and user

create database <databasename>;
create user <username> IDENTIFIED BY '<password>';
GRANT ALL ON <databasename>.* TO <username>@localhost IDENTIFIED BY '<password>';
flush privileges

Use the command exit to quit out of the mysql interface. You can now verify the database and user.

mysql -u <username> -p
show databases;

That’s all there is to it.

The above commands and the expected system output below:

You can import a sql dump file to the new database with the following command

mysql -u username -p new_database < data-dump.sql


Leave a Reply

Your email address will not be published. Required fields are marked *