Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to Print Out All Rows of a MySQL Table in Python?
Next article icon

A connector is employed when we have to use mysql with other programming languages. The work ofmysql-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 the MySQL database, we use Python-MySQL-Connector. Here we will try implementing SQL queries which will show the names of all the tables present in the database or server.

Syntax:

To show the name of tables present inside a database:

SHOW Tables;

To show the name of tables present inside a server:

SELECT table_name


FROM information_schema.tables;

Database in use:

Schema of the database used

The following programs implement the same.

Example 1:Display table names present inside a database:

Python3
importmysql.connectormydb=mysql.connector.connect(host="localhost",user="root",password="",database="gfg")mycursor=mydb.cursor()mycursor.execute("Show tables;")myresult=mycursor.fetchall()forxinmyresult:print(x)

Output:

Table names in gfg  database

Example 2: Display table names present inside a server:

Python3
importmysql.connectormydb=mysql.connector.connect(host="localhost",user="root",password="",)mycursor=mydb.cursor()mycursor.execute("SELECT table_name FROM information_schema.tables;")myresult=mycursor.fetchall()forxinmyresult:print(x)

Output:

Table names in server

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp