Skip to content

Install MariaDB

ReefSpy edited this page Mar 29, 2024 · 5 revisions

(refer to https://pimylifeup.com/raspberry-pi-mysql/ )

Installing MariaDB

sudo apt install mariadb-server -y
sudo mysql_secure_installation

when prompted for password, just hit ENTER (we will add password later):

Enter current password for root (enter for none): 

when prompted for unix_socket authentication, press "n"

Switch to unix_socket authentication [Y/n] n

When prompted to change root password, press "y"

Change the root password? [Y/n] y

Set password to ‘reefberry

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!

When prompted to remove anonymous users, press "y"

Remove anonymous users? [Y/n] y

When prompted to disallow root login remotely, press "y" (we will add a remote user later)

Disallow root login remotely? [Y/n] y

When prompted to remove the test database, press "y"

Remove test database and access to it? [Y/n] y

When prompted to reload privilege tables, press "y"

Reload privilege tables now? [Y/n] y

Next we will allow remote access to the database
(this is helpful while configuring and debugging things remotely):
(refer to https://webdock.io/en/docs/how-guides/database-guides/how-enable-remote-access-your-mariadbmysql-database )

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Change the value of bind-address to 0.0.0.0 then save changes (default was 127.0.0.1):

bind-address = 0.0.0.0 

create service account

Now login to the database command line as user "root" (use the password we set earlier)

sudo mysql -u root -p

We will create a new account fro the aquarium controller and grant full access to DB. This account will be able to login remotely from all IPs:

(run this command on MariaDB command line)

GRANT ALL ON *.* to 'pi'@'%' IDENTIFIED BY 'reefberry' WITH GRANT OPTION;

Exit the MariaDB command line:

quit;

restart database service

sudo systemctl restart mariadb