Table of Contents

How to Build a Database Server on a Raspberry Pi 4

By Ryan Cheevers-Brown:


This post is about creating a Raspberry Pi database server.

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


  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

🌸👋🏻 Let’s take this to your inbox. You’ll receive occasional emails about whatever’s on my mind—offensive security, open source, academics, boats, software freedom, you get the idea.

4. Network configuration

Note for RIT folks: Please note that this tutorial is using RIT’s legacy network. In May 2022, RIT will be using a new network. Thus, you may need to repeat this process after RIT sets up the new network. If you are not on RIT’s network or are following this tutorial after June 2022, you can disregard this note.

  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, 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 “” 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. It takes around thirty minutes for the Raspberry Pi to clear the network cache. 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 or ping
  3. Finish the setup on the PI monitor
    • Restart the PI

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


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
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 -u username -ppassword 
mysql -h -u oliviagallucci -padmin

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


If you enjoyed this post about building a Raspberry Pi database server, check out my other SWEN-261 articles.

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

Written by Olivia Gallucci

Olivia is an honors student at the Rochester Institute of Technology. She writes about security, open source software, and professional development.