MySQL seems to be coming out soon, but I will use it normally, so make a note of how to use it from Python.
Use MySQL-python. By the way, this library seems to be compatible with MariaDB.
python
pip install MySQL-python
If an error occurs in debian system
apt-get install python-dev
May be resolved by running
python
import MySQLdb
#Login to DB
#Optional for localhost
connection = MySQLdb.connect(db="test",user="test")
cursor = connection.cursor()
# SQL
cursor.execute("select * from users")
result = cursor.fetchall()
for row in result:
p row[0]
cursor.close()
connection.close()
Then, you can get the execution result of the SQL statement as an array row by row as a row.
Also, if you specify cursorclass = MySQLdb.cursors.DictCursor
for MySQLdb.connect,
row becomes a dictionary of column names and values.
Recommended Posts