Extract Data from Database using MySQL-Connector and XAMPP in Python Last Updated : 01 Nov, 2020 Comments Improve Suggest changes Like Article Like Report Prerequisites: MySQL-Connector, XAMPP Installation A connector is employed when we have to use MySQL with other programming languages. The work of mysql-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server. RequirementsXAMPP: Database / Server to store and display data.MySQL-Connector module: For connecting the database with the python file. Use the below command to install this module.pip install mysql-connector Wheel module: A command line tool for working with wheel files. Use the below command to install this module.pip install wheel Step-by-step Approach: Procedure to create a table in the database: Start your XAMPP web server.Type http://localhost/phpmyadmin/ in your browser.Go to Database create database with name and click on Create.Create a table with in GEEK database and click on Go.Define column names and click on save.Your table is created.Insert data in your database by clicking on SQL tab then select INSERT.The data in your table is:Now you can perform operation IE display data in your web page using python Procedure for writing Python program: Import mysql connector module in your Python code.import mysql.connector Create connection object. conn_object=mysql.connector.connect(hostname,username,password,database_name) Here, you will need to pass server name, username, password, and database name) Create a cursor object.cur_object=conn_object,cursor() Perform queries on database.query=DDL/DML etc cur_obj=execute(query) Close cursor object.cur_obj.close() Close connection object.conn_obj.close() Below is the complete Python program based on the above approach: Python3 # import required modules import mysql.connector # create connection object con = mysql.connector.connect( host="localhost", user="root", password="", database="GEEK") # create cursor object cursor = con.cursor() # assign data query query1 = "desc geeksdemo" # executing cursor cursor.execute(query1) # display all records table = cursor.fetchall() # describe table print('\n Table Description:') for attr in table: print(attr) # assign data query query2 = "select * from geeksdemo" # executing cursor cursor.execute(query2) # display all records table = cursor.fetchall() # fetch all columns print('\n Table Data:') for row in table: print(row[0], end=" ") print(row[1], end=" ") print(row[2], end=" ") print(row[3], end="\n") # closing cursor connection cursor.close() # closing connection object con.close() Output: Note: XAMPP Apache and MySQL should be kept on during the whole process. Comment More infoAdvertise with us Next Article Extract Data from Database using MySQL-Connector and XAMPP in Python sravankumar_171fa07058 Follow Improve Article Tags : Python Python-mySQL Practice Tags : python Similar Reads Connect MySQL database using MySQL-Connector Python While working with Python we need to work with databases, they may be of different types like MySQL, SQLite, NoSQL, etc. In this article, we will be looking forward to how to connect MySQL databases using MySQL Connector/Python.MySQL Connector module of Python is used to connect MySQL databases with 2 min read How to store XML data into a MySQL database using Python? In this article, we are going to store XML data into the MySQL database using python through XAMPP server. So we are taking student XML data and storing the values into the database. RequirementsXAMPP server: It is a cross-platform web server used to develop and test programs on a local server. It i 3 min read How to visualize data from MySQL database by using Matplotlib in Python ? Prerequisites: Matplotlib in Python, MySQL While working with Python we need to work with databases, they may be of different types like MySQL, SQLite, NoSQL, etc. In this article, we will be looking forward to how to connect MySQL databases using MySQL Connector/Python. MySQL Connector module of Py 5 min read Create Database in MariaDB using PyMySQL in Python MariaDB is an open source Database Management System and its predecessor to MySQL. The pymysql client can be used to interact with MariaDB similar to that of MySQL using Python. In this article we will look into the process of creating a database using pymysql. To create a database use the below syn 2 min read Create MySQL Database Login Page in Python using Tkinter Prerequisites: Python GUI â tkinter, Python MySQL â Select QueryTkinter is one of the Python libraries which contains many functions for the development of graphic user interface pages and windows. Login pages are important for the development of any kind of mobile or web application. This page is m 2 min read How To Connect and run SQL Queries to a PostgreSQL Database from Python In this PostgreSQL Python tutorial, we will explain how to connect to a PostgreSQL database using Python and execute SQL queries. Using the powerful psycopg2 library, we can seamlessly interact with our PostgreSQL database from Python, making it easy to perform tasks like inserting, updating, and re 4 min read CRUD Operation on Oracle Database Using Python In this article, we will learn how to perform CURD operations on an Oracle Database by using Python. Oracle Database is a Database Management System produced and marketed by Oracle Corporation. It supports the Structured Query language (SQL) to Manage and Manipulate the Data. As a prerequisite, you 4 min read Export Data From Mysql to Excel Sheet Using Python We are given a MySQL database and our task is to export the data into an excel sheet using Python. In this article, we will see how to export data from MySQL to Excel Sheets using Python. Export Data From Mysql to Excel Sheet Using PythonBelow are some of the ways by which we can export data from My 3 min read PostgreSQL - Connecting to the Database using Python PostgreSQL in Python offers a robust solution for developers looking to interact with databases seamlessly. With the psycopg2 tutorial, we can easily connect Python to PostgreSQL, enabling us to perform various database operations efficiently. In this article, we will walk you through the essential 4 min read Connecting to SQL Database using SQLAlchemy in Python In this article, we will see how to connect to an SQL database using SQLAlchemy in Python. To connect to a SQL database using SQLAlchemy we will require the sqlalchemy library installed in our python environment. It can be installed using pip - !pip install sqlalchemyThe create_engine() method of sq 3 min read Like