Learn how to Choose From MySQL in Python


First, you have to the mysql.connector. In case you are uncertain of how one can get this setup, consult with Learn how to Set up MySQL Driver in Python.

Learn how to Choose From a MySQL Desk in Python

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  person = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM prospects")
myresult = mycursor.fetchall()

for x in myresult:
  print(x)

Learn how to Choose Columns From a MySQL Desk in Python

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  person = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()
mycursor.execute("SELECT identify, tackle FROM prospects")
myresult = mycursor.fetchall()

for x in myresult:
  print(x)

Learn how to Fetch Solely a Single Row From MySQL in Python

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  person = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM prospects")
myresult = mycursor.fetchone()

print(myresult)
See also  The Energy of Two (2) Desk

Leave a Reply