-
Notifications
You must be signed in to change notification settings - Fork 1
/
mydb.py
26 lines (21 loc) · 864 Bytes
/
mydb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Install MySQL if you do not have it: https://www.w3schools.com/mysql/mysql_install_windows.asp#:~:text=The%20simplest%20and%20recommended%20method,%2D8.0.23.msi%20.
# pip install mysql
# pip install mysql-connector-python
# IF THE PREVIOUS CONNECTOR DOES NOT WORK, USE: pip install mysql-connector
# now run on your terminal: python mydb.py
# if "Db set up!" appears on your terminal, all worked well
# A video on how to set up django with mySQL is available here: https://www.youtube.com/watch?v=t10QcFx7d5k
import mysql.connector
import os
from dotenv import load_dotenv
load_dotenv()
dataBase = mysql.connector.connect(
host='localhost',
user='root',
passwd=os.environ.get('MY_SQL_ROOT_PASSWORD'),
)
# prepare a cursor object
cursorObject = dataBase.cursor()
# create db
cursorObject.execute("CREATE DATABASE pollnmysql")
print("Db set up!")