Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Create MySQL table from Python

import mysql.connector
try:
    connection = mysql.connector.connect(host='localhost',
                                         database='techshop',
                                         user='root',
                                         password='')
    mySql_Create_Table_Query = """CREATE TABLE Mobile ( 
                             Id int(11) NOT NULL,
                             Name varchar(250) NOT NULL,
                             Price float NOT NULL,
                             Purchase_date Date NOT NULL,
                             PRIMARY KEY (Id)) """
    cursor = connection.cursor()
    result = cursor.execute(mySql_Create_Table_Query)
    print("Mobile Table created successfully ")
except mysql.connector.Error as error:
    print("Failed to create table in MySQL: {}".format(error))
finally:
    if connection.is_connected():
        cursor.close()
        connection.close()
        print("MySQL connection is closed")
Comment

PREVIOUS NEXT
Code Example
Python :: import status in django rest framework 
Python :: How to generate the power set of a given set, in Python? 
Python :: pandas insert column in the beginning 
Python :: how to read the first line in a file python 
Python :: python replace backslash with forward slash 
Python :: dataframe from two series 
Python :: Counter to df pandas 
Python :: python how to get project location 
Python :: create an array from 1 to n python 
Python :: python ping ip address 
Python :: python cv2 screen capture 
Python :: import sklearn linear regression 
Python :: pandas group by month 
Python :: how to plot count on column of dataframe 
Python :: remove whitespace around figure matplotlib 
Python :: concat dataFrame without index reset 
Python :: portscan with python 
Python :: pytest ignore warnings 
Python :: pandas.core.indexes.base.index to list 
Python :: Find the Runner Up Score solution in python3 
Python :: extract ints from strings in Pandas 
Python :: correlation matrix python 
Python :: python heart code 
Python :: install python3 centos 7.8 
Python :: py sleep function 
Python :: log base 2 python 
Python :: anaconda python update packages 
Python :: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. 
Python :: debugging pytest in vscode 
Python :: add x axis label python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =