How to Print Out All Rows of a MySQL Table in Python? Last Updated : 26 Nov, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report MySQL server is an open-source relational database management system which is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a web server(here XAMPP) we use various modules in Python such as PyMySQL, mysql.connector, etc. In this article, we will see how to get the all rows of a MySQL table by making a database connection between python and MySQL. First, we are going to connect to a database having a MySQL table. The SQL query to be used to get all the rows: SELECT * FROM table-name Finally, after getting all the rows, display each row in the table using an iterator. Below are some programs which depict how to extract rows from a MySQL table in a Database: Example 1: Below is the table geeksdemo is database geek which is going to be accessed by a Python script: Below is the program to get all the rows in an MYSQL table: Python3 # import required modules import pymysql pymysql.install_as_MySQLdb() import MySQLdb # connect python with mysql with your hostname, # username, password and database db= MySQLdb.connect("localhost", "root", "", "GEEK") # get cursor object cursor= db.cursor() # execute your query cursor.execute("SELECT * FROM geeksdemo") # fetch all the matching rows result = cursor.fetchall() # loop through the rows for row in result: print(row) print("\n") Output: Example 2: Here is another example to extracts all the rows from a table in a given database, below is the table scheme and rows: Below is the Python script extract all each row from the table: Python3 # import required modules import MySQLdb import pymysql pymysql.install_as_MySQLdb() # connect python with mysql with your hostname, # username, password and database db = MySQLdb.connect("localhost", "root", "", "techgeeks") # get cursor object cursor = db.cursor() # execute your query cursor.execute("SELECT * FROM techcompanies") # fetch all the matching rows result = cursor.fetchall() # loop through the rows for row in result: print(row, '\n') Output: Comment More infoAdvertise with us Next Article How to Show All Tables in MySQL using Python? A anurag702 Follow Improve Article Tags : Python mysql Practice Tags : python Similar Reads How to Show All Tables in MySQL using Python? 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. In order to make python interact with 1 min read How to Count the Number of Rows in a MySQL Table in Python? MySQL server is an open-source relational database management system which is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a 2 min read How to Copy a Table in MySQL Using Python? In this article, we will create a table in MySQL and will create a copy of that table using Python. We will copy the entire table, including all the columns and the definition of the columns, as well as all rows of data in the table. To connect to MySQL database using python, we need PyMySql module. 3 min read How to Add a Column to a MySQL Table in Python? Prerequisite: Python: MySQL Create Table 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. Â ALTER statemen 4 min read How to Compute the Sum of All Rows of a Column of a MySQL Table Using Python? MySQL server is an open-source relational database management system that is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a w 2 min read How to list tables using SQLite3 in Python ? In this article, we will discuss how to list all the tables in the SQLite database using Python. Here, we will use the already created database table from SQLite. We will also learn exception handling during connecting to our database. Database Used: Â Steps to Fetch all tables using SQLite3 in Pytho 2 min read Like