MariaDB commands by Forest Admin
MariaDB is an open-source relational database management system [RDBMS] that is popular among web apps, online systems of various kinds, and software development in general.
It is a fork of MySQL and is known for its high performance and scalability. In this article, we will take a look at some of the most commonly used MariaDB commands that are essential for managing and working with a MariaDB database.
No waiting room here – let's dive in immediately.
Basic MariaDB commands
As with everything, let us ease into the simple stuff before a deeper dive.
SELECT: The SELECT statement is used to retrieve data from one or more tables in a database. The syntax of the SELECT statement is as follows:
For example, to select all the columns and rows from a table named "customers", you would use the following command:
INSERT: The INSERT statement is used to add new rows of data to a table. The syntax of the INSERT statement is as follows:
For example, to insert a new customer into the "customers" table, you would use the following command:
UPDATE: The UPDATE statement is used to modify existing data in a table. The syntax of the UPDATE statement is as follows:
For example, to update the address of a customer named "John Smith" in the "customers" table, you would use the following command:
DELETE: The DELETE statement is used to delete data from a table. The syntax of the DELETE statement is as follows:
For example, to delete a customer named "John Smith" from the "customers" table, you would use the following command:
CREATE: The CREATE statement is used to create a new table, database, or other database object. The syntax of the CREATE statement is as follows:
For example, to create a new table named "customers" with columns for "name", "address", and "phone", you would use the following command:
ALTER: The ALTER statement is used to modify the structure of an existing table or other database object. The syntax of the ALTER statement is as follows:
DROP: The DROP statement is used to delete an existing table, database, or other database object. The syntax of the DROP statement is as follows:
For example, to delete a table named "customers", you would use the following command:
Advanced MariaDB commands
Now that we've seen basic MariaDB commands, let's move to tougher ones.
TRUNCATE: The TRUNCATE statement is used to remove all data from a table, but leave the table structure intact. The syntax of the TRUNCATE statement is as follows:
For example, to remove all data from the "customers" table, you would use the following command:
SHOW: The SHOW statement is used to display information about the structure of a database or its objects. Some examples of the types of information that can be displayed using the SHOW statement include:
USE: The USE statement is used to select a database to work with. The syntax of the USE statement is as follows:
For example, to select a database named "mydb", you would use the following command:
JOIN: A JOIN command is used to combine rows from two or more tables based on a related column between them.
There are several types of joins such as INNER JOIN, OUTER JOIN, LEFT JOIN and RIGHT JOIN.
The syntax for joining two tables is as follows:
For example, to join the "customers" table and "orders" table on a "customer_id" column, you would use the following command:
UNION: The UNION operator is used to combine the result-set of two or more SELECT statements. The UNION operator selects only distinct values by default. If you want to include duplicate values, you can use the UNION ALL operator.
The syntax for UNION is as follows:
For example, to retrieve all the unique values from the "customers" table and the "orders" table, you would use the following command:
INDEXING: Indexing is a technique used to improve the performance of a database by providing faster access to the data. Indexes are used to quickly locate rows with specific column values without having to search the entire table.
There are several types of indexes available in MariaDB such as PRIMARY KEY, UNIQUE KEY, and FULLTEXT INDEX.
The syntax for creating an index is as follows:
For example, to create an index on the "customer_name" column of the "customers" table, you would use the following command:
It's important to keep in mind that too many indexes can also slow down the performance of a database, so it's essential to use them judiciously.
Final words
To effectively work with MariaDB, it is important to understand the commonly used MariaDB commands such as SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TRUNCATE, SHOW, and USE.
These commands are essential for managing and working with a MariaDB database.
In addition to these basic commands, MariaDB also supports advanced commands such as JOIN, UNION, and INDEXING.
Forest Admin integrates various RDBMS such as PostgreSQL, MySQL, MongoDB and Microsoft SQL Server.
Interested in learning more about Forest Admin and how we can help your business thrive?
If you feel like chatting with us because you're curious about what we do, please reach out.
If you want to know more about various Databases, here are a few articles we’ve written on the subject: