This folder contains everything needed to initialize and manage the database for the UFID Reader project. The database is hosted in a Docker container using MariaDB and is designed to store data for courses, exams, kiosks, users, and student rosters while being lightweight and efficient.
- Database: MariaDB hosted in a Docker container.
- Purpose: Stores data for courses, exams, kiosks, users, and student rosters, which is accessed by the backend and Raspberry Pi application.
- Connection: Accessible via LAN connections using TCP protocol.
-
docker-compose.yml:- Defines the Docker container for MariaDB.
- To intialize the container: (under this directory)
docker-compose up -d
-
/data:- Contains the database backup and a Python script for grabbing UF semester data as SQL files to import into the database:
ufid_database_backup.sql:- Backup file for the database.
API-to-Database.py:- Script to use UF's public API to grab an entire semester's course information.
insert_into_db.py:- Script to import any course/class sql file into the db.
- Contains the database backup and a Python script for grabbing UF semester data as SQL files to import into the database:
-
Docker:
- Install Docker and Docker Compose on your machine.
- Docker Installation Guide
-
MariaDB:
- Ensure MariaDB is installed locally if you need to export or import the database.
- MariaDB Releases
-
Start the Docker Container:
- Navigate to this directory and run:
docker-compose up -d
- This will create and start the necessary Docker containers, including the MariaDB container.
- Docker network is also instantiated for groundwork towards containerizing other components into docker
- Navigate to this directory and run:
-
Access the Database:
-
Ensure the container is running:
docker ps
If the container is not running, start it:
docker start ufid_mariadb
-
Access the database via MySQL:
mysql -h 127.0.0.1 -P 3306 --protocol=TCP -u myuser -p
Or directly through Docker:
docker exec -it ufid_mariadb mariadb -u myuser -p- Password:
mypass
- Password:
-
To create a backup of the database:
- Ensure the container is running.
- Run the following command:
docker exec ufid_mariadb mariadb-dump -umyuser -pmypass ufid_database > ufid_database_backup.sql
- The
ufid_database_backup.sqlfile will be created in this directory. Commit this file to version control if needed.
To restore the database from a backup:
- Ensure the container is running.
- Run the following command:
docker exec -i ufid_mariadb mariadb -umyuser -pmypass ufid_database < ufid_database_backup.sql
- The database will now be populated with the data from the backup.
To allow access from other machines on the same network:
-
Ensure the container is running.
-
Access the MariaDB container as root user:
docker exec -it ufid_mariadb mariadb -u root -p- Password:
mypass(should probably be updated for obvious security reasons)
- Password:
-
Grant access to other machines:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypass' WITH GRANT OPTION; FLUSH PRIVILEGES;
- Note: The
@'%'allows connections from any IP. For better security, replace%with a specific IP address.
- Note: The
-
Open the firewall on the host machine:
- Add an inbound rule to allow TCP traffic on port
3306. - Note: This adds an inboud rule that exposes a port to the DB which on a public network can be risky. For better security, consider exposing this port to only VPNs or private networks. Additionally if ported to a cloud VM, be sure to configure security groups to allow inbound traffic.
- Add an inbound rule to allow TCP traffic on port
-
Find the host machine's IP address:
ipconfig # On Windows- Look for the
IPv4 Addressunder theWireless LAN adapter Wi-Fisection. It should look something like:IPv4 Address. . . . . . . . . . .: 192.168.1.100
- Look for the
-
Update connection strings:
- Update the database connection strings in your project to use the host machine's IP address.
-
Verify the connection:
- Test the connection from a secondary machine to ensure the database is accessible.
- Because the docker container relies on LAN connectoins, and changes do not persist across environments/different docker containers. Use the export/import process to share updates.
- For development, it is recommended to use a Docker GUI for easier management of containers.
-
Remote Access:
- Set up the database on a remote server for secure access from anywhere, instead of relying on LAN connections.
- PLEASE PESTER DR. BLANCHARD ABOUT THIS!
-
Security:
- Use environment variables for sensitive information like database credentials.
- Encrypt data in transit.
For more details on how the database interacts with the system, refer to the Backend README.