Connect Python to MySQL Database

How to Connect Python to MySQL Database and Display Data

Connect Python to MySQL Database

In This Python Tutorial We Will See How To Connect Python To MySQL DataBase Using PIP in VsCode.








Source Code:


import mysql.connector

connection = mysql.connector.connect(
host='localhost',
user='root',
password='',
port='3306',
database='test_py'
)

c = connection.cursor()

select_query = 'SELECT * FROM `users_2`'
c.execute(select_query)
data = c.fetchall()

# display data
for row in data:
print(row)


OUTPUT:

How to Connect Python to MySQL Database and Display Data







Share this

Related Posts

Previous
Next Post »