import pandas as pd
import os
import os.path
import json
import sys
import importlib
module_dir = "../../modules"
module_path = os.path.abspath(module_dir)
if not module_path in sys.path:
sys.path.append(module_path)
import dbutil
importlib.reload(dbutil)
%load_ext sql
Edit
creds.json
to reflect your mysql user and passwordThis must be done prior to executing the following cell
dbsource = "sqlite"
db = "book"
cstring = dbutil.db_cstring(dbsource, "creds.json", ".", db)
print("Connection string:", cstring)
The cell below uses the Python variable constructed earlier to actually establish a connection with the server.
If you cannot get a connection established, switch over to MySQL Workbench and try from that different client.
%sql $cstring
Try and execute the following line, which uses an "inline" sql magic to exectute a query to the database and retrieve the result.
%sql SELECT * from indicators0
dbsource = "sqlite"
db = "school"
cstring = dbutil.db_cstring(dbsource, "creds.json", ".", db)
print("Connection string:", cstring)
%sql $cstring
%sql SELECT * from departments