How To Install And Configure MariaDB on Debian 11.3
To Install and Configure Mariadb on Debian 11.3
Introduction:
MariaDB is an open-source, fully compatible relational database management system (RDBMS) that makes adding new users and granting them privileges easy. Controlling access and permissions is a common task when managing a database.
Installation Procedure :
Step 1: Install the Mariadb-server by using the below command
root@debian:~# apt install mariadb-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
dbconfig-common dbconfig-mysql default-mysql-client icc-profiles-free libjs-bootstrap4 libjs-codemirror
libjs-jquery libjs-jquery-mousewheel libjs-jquery-timepicker libjs-jquery-ui libjs-openlayers libjs-popper.js
libjs-sizzle libjs-sphinxdoc libjs-underscore libonig5 libzip4 node-jquery
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
mariadb-server
0 upgraded, 1 newly installed, 0 to remove and 208 not upgraded.
Need to get 35.5 kB of archives.
After this operation, 73.7 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 mariadb-server all 1:10.5.19-0+deb11u2 [35.5 kB]
Fetched 35.5 kB in 0s (255 kB/s)
Selecting previously unselected package mariadb-server.
(Reading database ... 142102 files and directories currently installed.)
Preparing to unpack .../mariadb-server_1%3a10.5.19-0+deb11u2_all.deb ...
Unpacking mariadb-server (1:10.5.19-0+deb11u2) ...
Setting up mariadb-server (1:10.5.19-0+deb11u2) ...
Step 2: Check the MariaDB status by using the below command
root@debian:~# systemctl status mariadb
● mariadb.service - MariaDB 10.5.19 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-06-16 12:35:49 CDT; 1 weeks 0 days ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 607 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 4623)
Memory: 109.0M
CPU: 1.903s
CGroup: /system.slice/mariadb.service
└─607 /usr/sbin/mariadbd
Jun 16 12:35:49 debian mariadbd[607]: Version: '10.5.19-MariaDB-0+deb11u2' socket: '/run/mysqld/mysqld.sock' po>
Jun 16 12:35:49 debian systemd[1]: Started MariaDB 10.5.19 database server.
Jun 16 12:35:49 debian /etc/mysql/debian-start[694]: Upgrading MySQL tables if necessary.
Jun 16 12:35:50 debian /etc/mysql/debian-start[698]: Looking for 'mariadb' as: /usr/bin/mariadb
Jun 16 12:35:50 debian /etc/mysql/debian-start[698]: Looking for 'mariadb-check' as: /usr/bin/mariadb-check
Jun 16 12:35:50 debian /etc/mysql/debian-start[698]: This installation of MariaDB is already upgraded to 10.5.19->
Jun 16 12:35:50 debian /etc/mysql/debian-start[698]: There is no need to run mysql_upgrade again for 10.5.19-Mari>
Jun 16 12:35:50 debian /etc/mysql/debian-start[698]: You can use --force if you still want to run mysql_upgrade
Jun 16 12:35:50 debian /etc/mysql/debian-start[714]: Checking for insecure root accounts.
Jun 16 12:35:50 debian /etc/mysql/debian-start[722]: Triggering myisam-recover for all MyISAM tables and aria-rec>
Step 3: Enable the MariaDB by using the below command
root@debian:~# systemctl enable mariadb
Synchronizing state of mariadb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mariadb
Step 4: Install the MySQL secure installation and set the root passwd by using the below command
root@debian:~# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Step 5: Open the MariaDB Database by using the below command
root@debian:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.5.19-MariaDB-0+deb11u2 Debian 11
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Step 6: Create a new database by using the below command
MariaDB [(none)]> CREATE DATABASE MYSQL;
Query OK, 1 row affected (0.001 sec)
Step 7: Use the create database
MariaDB [(none)]> USE MYSQL;
Database changed
Step 8: Check the number of available databases
MariaDB [MYSQL]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| MYSQL |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)
Step 9: Create new user in database by using the below command
MariaDB [MYSQL]> CREATE USER 'USER1'@'localhost' IDENTIFIED BY'mysql@123';
Query OK, 0 rows affected (0.009 sec)
Step 10: Refresh the privileges by using the below command
MariaDB [MYSQL]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)
Step 11: Grant the privileges to MariaDB user by using the below command
MariaDB [MYSQL]> GRANT ALL ON *.*TO'USER1'@'localhost'WITH GRANT OPTION;
Query OK, 0 rows affected (0.002 sec)
Step 12: Refresh the privileges by using the below command
MariaDB [MYSQL]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)
Step 13: Grant the multiple privileges to MariaDB user by using the below command
MariaDB [MYSQL]> GRANT INSERT,UPDATE ON *.*TO'USER1'@'localhost';
Query OK, 0 rows affected (0.002 sec)
Step 14: Show the user Grant the privileges by using the below command
MariaDB [MYSQL]> SHOW GRANTS FOR 'USER1'@'localhost';
+-----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for USER1@localhost |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `USER1`@`localhost` IDENTIFIED BY PASSWORD '*4B4F5AF88255C46EB9281BD84ED0329C56937097' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
Step 15: Remove the MariaDB user account by using the below command
MariaDB [MYSQL]> DROP USER'USER1'@'localhost';
Query OK, 0 rows affected (0.002 sec)
Step 16: exit the MariaDB by using the below command
MariaDB [MYSQL]> exit;
Bye
Conclusion:
By this how to install and configure MariaDB has come to an end.
Comments ( 0 )
No comments available