Creating a Database and a Database User with a Password in MariaDB
Introduction to MariaDB and MySQL
MariaDB and MySQL are two of the most popular open-source relational database management systems (RDBMS) used for storing, organizing, and retrieving data. MariaDB was created as a fork of the MySQL database in response to concerns over its acquisition by Oracle Corporation. It aims to maintain high compatibility with MySQL and is widely used in the web and cloud hosting industries.
Step 1: Log in to the MariaDB shell
To log in to the MariaDB shell, open a terminal window and enter the following command:
1
$ mysql -u <username> -p
Replace <username> with the username you use to log in to the MariaDB server.
Step 2: Create a new database
To create a new database in MariaDB, enter the following command in the MariaDB shell:
1
MariaDB [(none)]> CREATE DATABASE <database_name>;
Replace <database_name> with the name you want to give to the new database.
Step 3: Create a new user and set a password
To create a new user in MariaDB and set a password, enter the following command in the MariaDB shell:
Replace <database_name> with the name you want to give to the new database.
Step 3: Create a new user and set a password
To create a new user in MariaDB and set a password, enter the following command in the MariaDB shell:
1
MariaDB [(none)]> CREATE USER '<user_name>'@'<host>' IDENTIFIED BY '<password>';
Replace <user_name> with the name you want to give to the new user, <host> with the host from which the user will connect to the database, and <password> with the password you want to set for the user.
Step 4: Grant permissions to the new user
To grant permissions to the new user in MariaDB, enter the following command in the MariaDB shell:
1
MariaDB [(none)]> GRANT ALL PRIVILEGES ON <database_name>.* TO '<user_name>'@'<host>';
Replace <database_name> with the name of the database you created in Step 2, <user_name> with the name of the user you created in Step 3, and <host> with the host from which the user will connect to the database.
Step 5: Flush the privileges and exit the MariaDB shell
To flush the privileges and exit the MariaDB shell, enter the following commands in the MariaDB shell:
console
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
console
And that’s it! You’ve successfully created a new database and a new user with a password in MariaDB.
Comments powered by Disqus.