MySQL Connector | Connect Python and MySQL using MySQL Connector
To install python connector Open cmd and type pip install mysql-connector-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.
Ø Python MySQL Connector is a Python driver that helps to integrate Python and MySQL. This Python MySQL library allows the conversion between Python and MySQL data types.
# Python program to connect to mysql database
import mysql.connector
# Connecting from the server
conn = mysql.connector.connect(user='root',host = 'localhost',database = 'raisdb',password='Mysql_Server@312')
dict = {
'Name': 'Online Smart Trainer', 'ID': 'LRDS1605016','College Name': 'LIET'
}
a=10
b=20
if conn.is_connected():
print("Connection is established....")
print(dict)
print("Addition of numbers", a+b)
# Disconnecting from the server
conn.close()
Save Above program in notepad file with .py extension
Open Python IDLE (3.11 64-bit) >>> File >>> Open >>> run
Output:
Comments
Post a Comment