MariaDB beginner management commands
Earlier, we learned to install the MariaDB server on CentOS/RHEL 7 (SEE), which is now the default database of RHEL/CentOS 7. Now we will discuss some useful MariaDB management commands. These are some very basic commands that allow you to start using MariaDB. These commands can also be used with MySQL, because Mariadb only supports the MySQL version.
MariaDB management commands
Check your MariaDB installed version
To check the current version of the database, enter the following command in the terminal:
$ Mysql-version
This command provides you with the current version of the database. In addition, you can run the commands mentioned below to view the detailed version,
$ Mysqladmin-u root-p version
Log on to mariadb
To log on to the mariadb server, run
$ Mysql-u root-p
Then enter the password to log on to the session.
Show all databases
To display all current databases of your maridb, run
$ Show databases;
After you log on to mariadb.
Create a new database
To create a new database in mariadb, run
$ Create database bkjia;
When you log on to mariabdb. To create a database directly from the terminal, run
$ Mysqladmin-u user-p create bkjia
Bkjia is the name of the new database.
Delete Database
To delete a database, run
$ Drop database bkjia;
Log on to the session from mariadb. Or you can use it,
$ Mysqladmin-u root-p drop bkjia
Note: If the "Access Denied" error occurs when running the mysqladmin command, it may be because we do not grant the root permission. To do this, run the command mentioned at and replace the user name with root.
Create a new user
To create a new user for the database, run
$ Create user 'bkjia '@ 'localhost' identified by 'Password ';
Allow users to access the database
To provide users with access to a single database, run
$ Grant all privileges on test. * to 'bkjia '@ 'localhost ';
This gives you full database naming test permissions. You can also grant SELECT, INSERT, and DELETE permissions.
To provide access to all databases, use *
$ Grant all privileges on *. * to 'bkjia '@ 'localhost ';
Create Database Backup/dump
To create a single database, run the following command in the terminal window,
$ Mysqldump-u root-p database_name> db_backup. SQL
To create backups for multiple databases in a single command,
$ Mysqldump-u root-p--databases db1 db2> db12_backup. SQL
To create a dump for all databases in a single command,
$ Mysqldump-u root-p--all-databases> all_dbs. SQL
Recover database from dump
To restore the database from the dump, run
$ Mysql-u root-p database_name <db_backup. SQL
However, this command can only be used without the same database name. To recover the database to any created database, run the 'mysqlimpport' command,
Mysqlimport-u root-p database_name <db_backup. SQL
Change the user password in mariadb
In this example, we want to change the "root" password, but you can use the following procedure to change the password of any user,
Log on to mariadb and select the 'mysql' database,
$ Mysql-u root-p
$ Use mysql;
Then run the following,
$ Update user set password = PASSWORD ('your _ new_password_here ') where User = 'root ';
Next, reload the permission,
$ Flush privileges;
Then exit the session.
This is a useful tutorial for managing MariaDB commands. Please leave your comments or suggestions in the comment box below.
For more MariaDB tutorials, see the following:
Install Nginx, MariaDB, and HHVM on Ubuntu 16.04 LTS to run WordPress
Install MariaDB in Ubuntu 16.04 Dockerfile
Linux Tutorial: How to check the MariaDB server version
How to install MariaDB in Ubuntu 16.04
CentOS 7.3 binary installation of MariaDB10.2.8 steps
CentOS 7 build and install MariaDB-10.1.22
How to migrate MySQL 5.5 database to MariaDB 10 on Ubuntu
Install MariaDB on the Ubuntu 14.04 (Trusty) Server
MariaDB details: click here
MariaDB's: click here