HomeSoftware EngineeringThe best way to Create a MySQL Desk in Python

The best way to Create a MySQL Desk in Python


If it’s worthwhile to create a desk in a MySQL database utilizing Python, then you are able to do the next.

The best way to Create a MySQL Desk in Python

import mysql.connector

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

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE folks (identify VARCHAR(255), tackle VARCHAR(255))")

The best way to Test if a MySQL Desk Exists in Python

import mysql.connector

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

mycursor = mydb.cursor()

mycursor.execute("SHOW TABLES")

for x in mycursor:
  print(x)
RELATED ARTICLES

Most Popular

Recent Comments