This document goes through the process of accessing the database either through the MySQL CLI or MySQL Workbench. It is intended for developers of the project.
If you haven't already, run the webapp/start-database.sh
script. Ensure that the docker service is running on your machine.
If you get a question of whether or not to create a password, choose yes
.
After the script is done running, the DATABASE_URL
field in your .env
file should look something like this.
To populate the database with mock data, run the populate-database.sh
script from the webapp
folder. Ensure that you are in the webapp
folder due to filepath restrictions in Python. For the underlying Python script to function, ensure you have the mysql-connector package - install this using the command
pip3 install mysql-connector-python
, alternatively pip install mysql-connector-python
.
DATABASE_URL="mysql://root:{password}@localhost:3306/ntnu-kpro-ai-assistant"
Where {password}
is the autogenerated password you got from running the start script.
Copy this password, you will need it in the next step.
If you haven't already, download MySQL Workbench
Open MySQL workbench and add a new connection.
Enter a connection name.
Make sure that the hostname is either localhost
or 127.0.0.1
(the loopback address).
Click Ok
.
When prompted with a password input, paste your password you copied earlier. If you want, you could store this password in the vault so you don't need to enter it every time.
That's it. The database is now accessible through the GUI, and the schemas
tab takes you to the database tables.
Run the following command from anywhere on your machine.
docker exec -it ntnu-kpro-ai-assistant-mysql mysql -p
You will then be prompted with a password input. Paste in your password you copied earlier.
You are now in the MySQL CLI.
The final step is to select the database. Run the following command
use ntnu-kpro-ai-assistant;
Now you can run SQL queries to the database.