Answers for "Connect to MySQL Using Connector Python C Extension"

0

Connect to MySQL Using Connector Python C Extension

import mysql.connector
from mysql.connector import Error
try:
    connection = mysql.connector.connect(host='localhost',
                                         database='techshop',
                                         user='root',
                                         password='', use_pure=True)
    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL database... MySQL Server version on ", db_Info)
except Error as e:
    print("Error while connecting to MySQL", e)
finally:
    if connection.is_connected():
        connection.close()
        print("MySQL connection is closed")
Posted by: Guest on April-10-2022

Code answers related to "Connect to MySQL Using Connector Python C Extension"

Python Answers by Framework

Browse Popular Code Answers by Language