Adding new enum column to an existing MySQL table using Python
Prerequisite: Python: MySQL Create Table
In this article, we are going to see how to add a new enum column to an existing MySQL table using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python for communicating with a MySQL database.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Database table in use:
We are going to use geeks(Database name) database and table describing the salary.
- Import module.
- Make a connection request with the database.
- Create an object for the database cursor.
- Execute the following MySQL query:
ALTER TABLE table_name ADD colunm_name ENUM('field1','field2',...)
- And print the result.
Below is the implementation with python:
Let’s check on SQL shell: