To better understand SQL and how to make a GUI in python, I created a virtual address book. My SQL based address book provides a GUI to perform CRUD operations as well as visually traverse the entries within the address book. This was hosted on a Raspberry Pi, but the general workflow is replicable on other playforms and operating systems.
- Download MariaDB
- Open Terminal
- Enter this to download MariaDB:
sudo apt-get update
sudo apt-get install mariadb-server- When prompted, enter
Y(yes) to continue - Enter:
sudo mysqld --console- Open up a new terminal
- Enter this to become a super/root user with all permissions:
sudo mysql- Enter:
create user ‘jake’@’localhost’ identified by ‘xxxx’;
grant all on *.* to ‘jake’@’localhost’;
quit
mysql -u jake -p
xxxx- To download python driver, enter:
sudo apt-get install python3-pymysql- To show databases, enter:
show databases;- To enter database, enter:
use [DATABASE NAME];Now that we are in a database, we will create and change data of a table. In this example, we will use the table entitled, "addressBook". 3. To show tables, enter: (this may be empty if no tables have been made)
show tables;- To create a table to store data for an address book, enter:
create table addressBook (name varchar(50), street varchar(50), city varchar(50), state varchar(50), state varchar(50), zip int(5));- To describe a table's structure and parameters for each attribute and its datatype, enter:
describe addressBook;- To insert values to the addressBook table, enter:
insert into addressBook values (‘Jake Walker’, 123 Old Town Road’, ‘San Jose’, ‘CA’, 95120);- To delete entries from the addressBook with a specified string assigned to an attribute of the table, enter:
Delete from addressBook where [TABLE ATTRIBUTE NAME] = [STRING]