Using Python to set up tables on MariaDB server
This repo provides an example of how to create a table on a mariaDB server, using a python script.
-
Python3 installed
-
Relational Database Server (I'm using MySQL/MariaDB)
-
An existing Database on the server.
-
Clone this repository
cd /your/favourite/directory git clone https://github.com/Syab/db-setup-mariadb-python cd db-setup-mariadb-python -
Create a file to hold your environment variables and secrets
# Linux systems touch env.profile #add this to your env.profile file #!/bin/bash export DBHOST="localhost" <or a valid IP to your DB> export DBUSER="<your user name to the db>" export DBPW="<your password name to your db>" export DBPORT="3306" <or any exisiting port you are using> export DBNAME="<your existing database>" -
Source the environment file
source env.profile -
Run the python script
python createtable.py -
You should have 1 table created with 4 columns :
- _id
- long_url
- short_url
- time_created