In this article, we will learn to create a Table in MySQL using Python. If you are looking for ‘how to make table in python’ this article will help you for the same.
To install SQL dependencies for Python, use the following command:
pip install mysql-connector
A Table is a collection of data organized in the form of rows and columns. Table is present within a database. Rows are also called tuples. Columns are called the attributes of the table
To create a table in MySQL, use the “CREATE TABLE” statement.
Make sure to define the connection properly. Below is an sample code for creating table in Python.
import mysql.connector mydb = mysql.connector.connect( host = "localhost", user = "username", password = "password", database = "mydatabase" ) cursor = mydb.cursor() cursor.execute("CREATE TABLE sample (name VARCHAR(20), place VARCHAR(50))")