Table of Contents

How to Build a Database Server on a Raspberry Pi 4

By Ryan Cheevers-Brown:

Introduction

Here’s how I turned a Raspberry Pi 4 into a MariaDB (MySQL) database server for my SWEN-261 team.

What do you need?

  • Raspberry Pi 4 Kit
  • A spare USB attachable mouse
  • A spare USB attachable keyboard
  • A monitor that allows HDMI input

1. Build the Pi

You can follow the instructions that came with your Pi, or you can watch this video.

2. Flash the SD card

  • Plug the SD card into a computer
  • Download the Raspberry Pi OS Installer.
  • Watch a video tutorial here
    • I kept all of the default options when flashing my SD card.

3. Set up the Pi

You will need:

  • A spare USB attachable mouse
  • A spare USB attachable keyboard
  • A monitor that allows HDMI input

Steps

  1. Insert the SD card into the PI
  2. Plug in the Pi’s HDMI port into a monitor
  3. Plug USB keyboard and USB mouse into the two USB ports on the Pi.
  4. Turn on monitor
  5. Choose your username and password
  6. Select US English language and US keyboard layout; or your language and keyboard layout of choice.
  7. Click next

🌸👋🏻 Enjoying this post? Get the next issue of [ret]2read. Once a month, I’ll email you whatever’s on my mind, usually Apple security research, offensive security, open source software freedom, and operating system internals.

4. Network configuration

Note for RIT folks: I wrote this on RIT’s legacy network, which RIT replaced in 2022, so the registration steps may differ now.

  1. Once you reach the network configuration stage, press Control + alt + t to open the terminal.
  2. On the terminal type ifconfig to get the MAC and IP address.
    • If you are using WiFi, take note of the wlan0 IP and MAC addresses. If you are using ethernet, take note of the eth0 IP and MAC addresses.
    • Steps for RIT students only
      • On a separate device not connected to the PI. Navigate to https://start.rit.edu/, and select “Computers” → “Advanced Registration” → type in MAC or IP address. From there, select “New registration,” and type in a name for your device like “happyserver.student.rit.edu.” Then, select the linux desktop checkbox and click “Register.”
      • If you cannot find the proper network on the PI or are assigned the wrong IP address, shutdown the Pi for 30 minutes. RIT’s network can take about 30 minutes to pick up a new registration. Then, power on the Pi. You will know if the IP address is assigned if you can ping the address or network name or IP address you assigned to it.
        • ping myserver.student.rit.edu or ping 123.1.2.3
  3. Finish the setup on the PI monitor
    • Restart the PI

Want your company or product in front of [ret]2read readers?
One sponsor per issue →

5. Connect to server via SSH

Once the IP address has been assigned. SSH into the server by opening a terminal on a device not connected to the Raspberry Pi

ssh johndoeserver.student.rit.edu

6. Install server tools

# install mariadb 
sudo apt install mariadb-server

# configure mysql security 
sudo mysql_secure_installation

If prompted, disallow anonymous users, remove test databases, and disallow remote root login.

# install apache2
sudo apt install apache2

# start apache2
sudo service apache2 start

# install phpmyadmin
sudo apt install phpmyadmin

Once you get to the web server step, press space to select “apache2,” and select “Ok.” This will install apache2. Then, if prompted for TCP/IP or Unix Socket, select “Unix Socket.” Keep defaults for everything else.

Set up your phpmyadmin account. You will be prompted during installation.

# install php
sudo apt install php 

# restart apache2
sudo service apache2 restart 

7. Set up the database on the server

  1. Download your database. In this case, I used a book database file on GitHub. This database file was for Group 2’s SWEN 261 (Kiser) project in Spring of 2022.
  2. Open a browser, and login to your server (see link below)
  3. Navigate to import (see image below)
  4. Import the database
# server link
servername.student.rit.edu/phpmyadmin
phpmyadmin import page. Used on a post about Raspberry Pi database server.

8. Connect to the server

Open a terminal and connect to the server in this format:

# general format 
mysql -h servername.student.rit.edu -u username -ppassword 
mysql -h servername.student.rit.edu -u oliviagallucci -padmin

Note: do not leave a space between the “p” and the password.

Conclusion

More from SWEN-261.

Portrait of Olivia Gallucci in garden, used in LNP article.

Written by Olivia Gallucci

Olivia is senior security engineer, certified personal trainer, and freedom software advocate. She writes about offensive security, open source software, and professional development.

Discover more from [ret]2read

A Monthly OS Internals Publication by Olivia Gallucci. Subscribe now to keep reading and get access to the full archive.

Continue reading