Can someone share example codes in Flask on how to access a MySQL DB? There have been documents showing how to connect to sqlite but not on MySQL.
Thank you very muc
mysql version: 5.7
Using mysql-connector. To install mysql-connector package in python3.
python3 -m pip install mysql-connector
To Connect with your database and querying, use following lines of code in your python script:
import mysql.connector
database=mysql.connector.connect(host='localhost',user='user',passwd='password',datbase='dbname')
cursor=database.cursor()
query="select * from test_table"
cursor.execute(query)
database.commit()