Home / Interview / MariaDB :: General Questions

Interview :: MariaDB

1) What is MariaDB?

MariaDB is a popular, open source, and the community-based project developed by MySQL developers. It is a relational database management technology which provides the same features as MySQL. It is a new replacement for MySQL.

MariaDB turns data into structured wide array of applications, ranging from banking to websites. MariaDB is used because it is fast, scalable, and robust with a reach ecosystem of storage engine, plugin, and many other tools make it versatile for a wide variety of use cases.

The latest version of MariaDB (version 10.4) also includes GIS and JSON features.

2) What are the main features of MariaDB?

MariaDB provides the same features of MySQL with some extensions. It is relatively new and advance.

A list of the features of MariaDB:

  • MariaDB can run on different operating systems and support a wide variety of programming languages.
  • MariaDB is licensed under GPL, LGPL, or BSD.
  • MariaDB follows a standard and popular query language.
  • MariaDB provides Galera cluster technology.
  • MariaDB provides supports for PHP which is the most popular web development language.
  • MariaDB includes a wide selection of storage engines, including high-performance storage engines for working with other RDBMS data sources.
  • MariaDB also offers many operations and commands unavailable in MySQL and eliminates/replaces features impacting performance negatively.
  • MariaDB's speed is one of its prominent features. It is remarkably scalable and can handle tens of thousands of tables and billions of rows of data.
3) How to create database in MariaDB?

CREATE DATABASE command is used to create a database in MariaDB, CREATE SCHEMA is a synonym for creating a database.

Syntax:

If the optional OR REPLACE clause is used, it acts as a shortcut for:

IF NOT EXISTS:

When IF NOT EXISTS clause is used, MariaDB will return a warning instead of an error if the specified database is already exist.

For example

Output:

 Query OK, 1 row affected (0.01 sec) 

Output:

 Query OK, 2 rows affected (0.00 sec) 

Output:

 Query OK, 1 row affected, 1 warning (0.01 sec)  

Warning:

Level Code Message
Note 1007 Can't create database 'student' ; database exists

SHOW DATABASE: This command is used to see the database you have created

Syntax:

4) How to use database in MariaDB?

USE DATABASE command is used to select and use a database in MariaDB. The USE db-name' statement tells MariaDB to use the db_name database as default (current) database for subsequent statements. The database remains the default until the end of the session, or another USE statement is issued:

Syntax:

Example

5) How to delete a database in MariaDB ?

DROP DATABASE command is used to drop a database in MariaDB. Be very careful with this statement! To use a DROP DATABASE, you need to DROP privileges on the database. DROP SCHEMA is a synonym for DROP DATABASE

NOTE: When a database is dropped, user privileges on the database are not automatically

Syntax:

IF EXISTS statement:

Use IF EXISTS to prevent an error from occurring for the database that does not exist. A note is generated for each non-existent database when using IF EXISTS statement.

Example

Output:

 Query OK, 0 rows affected (0.39 sec)  

Output:

 ERROR (1008): can't drop database; database doesn't exists [\]w: show warning enabled 

Output:

 Query OK, 0 rows affected, 1 warning (0.00 sec) 

Note (code 1008): can't drop database 'student'; database doesn't exists

6) How to create a table in MariaDB's database?

First, you have to create a database in MariaDB follows by selecting the database and then create a table by using the CREATE TABLE statement. You must have the CREATE privilege for a table or on the database to create a table.

Create table statement creates a table name followed by a list of columns, indexes, and constraints. By default, a table is created in the default database

Syntax:

For example

Output:

 Query OK, 0 rows affected (0.312 sec) 

You can verify that whether the table is created by using SHOW TABLES command.

7) How to delete a table in MariaDB's database?

DROP TABLE command is used to delete a table from a database in MariaDB. It deletes the table permanently and cannot be recovered. You must have DROP privilege for each table. All table data and the table definitions are removed, as well as triggers associated with the table so very careful with this statement!

If any of the tables named in the argument list do not exist, MariaDB returns an error indicating by name which not existing tables it was not unable to drop, but it also drops all of the tables in the list that does exist.

Syntax:

Example

Mariadb Drop table 1

You can verify whether the table is deleted or not.

Output

Mariadb Drop table 2
8) How to insert records in a table in MariaDB database?

INSERT INTO statement is used to insert records in a table in the MariaDB database.

Syntax:

Or

Or you can use it also with WHERE condition

For example

Specify the column name:

Insert more than 1 row at a time:

Select from another table:

9) How to retrieve records from a table in MongoDB database?

The SELECT statement is used to retrieve records from a table in the MongoDB database. You can choose, single, multiple or all records from a table by using different keywords.

Syntax:

FROM clause indicates the table or tables from which to retrieve rows.

The SELECT statement can be used with UNION statement, ORDER BY clause, LIMIT clause, WHERE clause, GROUP BY clause, HAVING clause, etc.

Example

We have a table "Students", having some data. So retrieve all records from "Students".

Mariadb Select data 1
10) How can you retrieve limited number of records from a table?

LIMIT clause is used with SELECT statement to select a limited number of records from a table. It facilitates you to retrieve records according to your use.

Syntax:

Example

Retrieve records in descending order:

Let's use SELECT statement with LIMIT clause in "Students" table. The result is displayed in descending order and LIMIT is 4.

Mariadb Select limit 1