This article is a quick note of installing MariaDB database management system on the Raspberry Pi board to store and manage data. It creates a unique database for users who can log into the Raspberry Pi’s system.
Installation procedure
System update
- sudo apt update
- If there is an item that needs to be upgraded, run the following commands to perform the upgrade.
sudo apt -y upgrade
Install MariaDB
sudo apt install mariadb-server
Setup and Security
- Enter the security settings program with the following commands.
sudo mysql_secure_installation - Steps for assigning a password to the MariaDB root
- Enter the original password of the root (MariaDB) that you have set. If it hasn’t been set up before, press the enter key for the next step.
- Enter the desired root password.
- Enter the root password again to confirm.
- Answer ‘y’ to the following security topics.
- Remove anonymous users
- Disallow root login remotely
- Remove the test database
- Answer ‘y’ to reload the system privileges.
Create a database for users
- Enter MariaDB database management in CUI (Console User Interface) or text mode with the following commands.
sudo mysql -u root -p - Enter root password
- Create a database with the following command.
CREATE DATABASE db_name ; - Create users (If this user has not been added before)
CREATE USER ‘ชื่อ’@’localhost’ IDENTIFIED BY ‘รหัสผ่าน’ ; - Assign management permissions to the database created in step 3 to the user in step 4 with the following command.
GRANT ALL PRIVILEGES ON ชื่อฐานข้อมูล.* TO ‘ชื่อ’@’localhost’ ; - Update the permissions with the command below.
FLUSH PRIVILEGES ; - Exit MariaDB database manager with the following command.
exit
Conclusion
From this article before proceeding to assign user privileges in the system, you must first design who can access to which database. And when it comes to the process of creating a database and granting permissions, it can be done easily.
Finally, I hope this article will be useful for those who want to install a structured database management system on the Raspberry Pi board’s Raspbian operating system.
CREATE DATABASE db_name;
and more
SHOW DATABASES;
USE db_name;
SHOW TABLES;
SELECT * FROM table;
INSERT INTO table VALUES( … );
DELETE FROM table WHERE condition;
UPDATE table SET … WHERE condition;
Reference
(C) 2020, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-08-26