Earlier we have learned to install & secure MariaDB server on Centos/RHEL 7, which is now the default database of RHEL/CentOS 7 onwards. We will now discuss some useful MariaDB commands. These are some very basic commands that will get you started with using MariaDB & these can also be used with MySQL since MariaDB is a forked out version of MySQL only.
(Recommended Read: MongoDB installation & configuration on RHEL/CentOS)
- Checking version of your MariaDB installation
To check the current version of your DB installation, type the following command in your terminal
This command provides you with the current version of DB. Alternatively, you can also run the below-mentioned command for a detailed view of the version,
- Logging into MariaDB
To log into the mariadb server, run
& then enter a password to login into the session.
- Showing all database
To show all the databases that your MariaDB currently has, run
after you are logged into mariadb.
- Creating new databases
To create a new database in mariadb, run
when logged into MariaDB. To create a database directly from the terminal, run
Here, dan is the name of the new database.
- Deleting a database
To delete a database, run
from the logged-in session of mariadb. Alternatively, you can also use,
Note:- If you are getting an ‘access denied’ error while running the mysqladmin commands, that might be because we have not given rights to root. To do so, run the command mentioned in point 7, replacing the name of the user with root.
- Creating new user
To create a new user for the database, run
- Granting access to the user for a database
For providing access to the user for a single database, run
This will provide user dan's complete access over database named test. We can also grant SELECT, INSERT, DELETE permissions to users.
To provide access to all database, replace test with * i.e.
- Creating backup/dump of the database
To create a single database, run the following command from your terminal window,
To create a backup of multiple databases in a single command,
To create a dump of all databases in a single command,
- Restoring database from the dump
To restore the database from a dump, run
But this command will work only when there is no previous database by the same name. if you want to restore database data to any already created database, we need to use the ‘mysqlimport ’ command,
- Changing password for a user in mariadb
We are going to change the password of ‘root’ for this example but you can use the below process to change the password of any user,
Login into mariadb& select ‘mysql’ database,
& then run the following,
Next, reload the privileges,
& then exit the session.
This was our tutorial on some useful MariaDB commands. Please do leave your comments or suggestions in the comment box below.