MariaDB Database Basic

Database is the key things of MariaDB, so crating database, and it’s access is key part of MariaDB tutorial, here you will learn about those area.


Objectives

  • MariaDB Database Create

  • MariaDB Drop Database

  • MariaDB Database Create User Grant Permission


MariaDB Database Create

Common way to crate database in MariaDB

Syntax

CREATE DATABASE <database_name>;

-- OR

CREATE DATABASE IF NOT EXISTS <database_name>;

Example

CREATE DATABASE my_website_database;
-- OR
CREATE DATABASE IF NOT EXISTS my_website_database;


Create database with character set & collate

Syntax

CREATE DATABASE <database_name> CHARACTER SET <character_set> COLLATE <collate>;
-- OR
CREATE DATABASE IF NOT EXISTS <database_name> CHARACTER SET <character_set> COLLATE <collate>;

Example

CREATE DATABASE IF NOT EXISTS my_website_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;


MariaDB Drop Database

Syntax

DROP DATABASE <database_name>;
--- OR
DROP DATABASE IF EXISTS <database_name>;

Example

DROP DATABASE my_website_database;
--- OR
DROP DATABASE IF EXISTS my_website_database;


MariaDB Database Create User Grant Permission

Syntax

GRANT ALL PRIVILEGES ON <database_name>.<table_name> TO 'username'@'hostname' IDENTIFIED BY 'password';


Example

Assumed user is hmtmcse and the host is localhost, database is my_website_database, password is password, and give full permission to database and all tables

GRANT ALL PRIVILEGES ON my_website_database.* TO 'hmtmcse'@'localhost' IDENTIFIED BY 'password';

FLUSH PRIVILEGES; --- Used for reload the access control


MariaDB Database Video tutorial