The steps I took to set up MariaDB server using an old Raspberry Pi 2 B running the most recent version of
Note: This would probably be better on a Raspberry Pi 4, but they are currently impossible to get at a reasonable price
- Update Raspberry Pi if needed
sudo apt update
sudo apt upgrade
- Install MariaDB server
sudo apt install mariadb-server
- Set up root access (modify as needed)
sudo mysql_secure_installation
- Connecting as root
sudo mysql -u root -p
Then in mysql
GRANT ALL PRIVILEGES on *.*
TO 'root'@'%';
FLUSH PRIVILEGES;
You will also probably need to do this
SET PASSWORD FOR 'root'@'%' = PASSWORD("AStrongPwd");
- Test this by running the following
mysql -u root -h localhost -p
- Create a new user (so you don't need to continue to use root)
CREATE USER '<user>'@'%';
SET PASSWORD FOR '<user>'@'%' = PASSWORD("AStrongPwd");
GRANT ALL PRIVILEGES on *.*
TO '<user>'@'%';
FLUSH PRIVILEGES;
These steps are a combination of steps from
The above will work to start using MariaDB SQL server; however, my microSD card is really tiny (8 GB).
Here is how I set up a 1 TB USB drive as my data directory
- Insert the USB drive and check the block name of the drive partition you want your database to be on
lsblk
- Mine was sda1 (yours might be different)
- Unmount the drive and format it to ext4
sudo umount /dev/sdXX # Change sdXX to whatever your drive is
sudo mkfs.ext4 /dev/sdXX -L database
- Create a mount point for your drive
sudo mkdir /mnt/database
- Edit your /etc/fstab (using vim, nvim, nano, etc.) as root (sudo) and insert the following
/dev/sda1 /mnt/database ext4 defaults 0 0
- Mount your drive to /mnt/database
sudo mount -a
- Clone /var/lib/mysql to /mnt/database/
sudo rsync -a /var/lib/mysql /mnt/database/
- Edit (using vim, nvim, nano, etc.) as root (sudo) /etc/msql/mariadb.conf.d/50-server.cnf and edit the following line
data.dir = /mnt/database/mysql
- Restart MariaDB
sudo systemctl restart mysql
These steps were modified from this thread