How you can Create a MySQL Desk in Python


If that you must create a desk in a MySQL database utilizing Python, then you are able to do the next.

How you can 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 individuals (identify VARCHAR(255), deal with VARCHAR(255))")

How you can Examine 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)

Leave a Reply