Why I am unable to create connection with MySQL using python on Window 11 OS
The program terminates automatically without throwing any error or output
Server is also running on port 3306. Id and pass is also correct but still no output terminal just gets closed while connecting and IDLE restarts automatically.
The port and connector working fine and details are given below.
C:\Users\jsr>pip list
Package Version
---------------------- -------
mysql-connector-python 9.1.0
pip 24.3.1
C:\Users\jsr>netstat -an | findstr 3306
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP 0.0.0.0:33060 0.0.0.0:0 LISTENING
TCP [::]:3306 [::]:0 LISTENING
TCP [::]:33060 [::]:0 LISTENING
_________________________________
Python code-
import mysql.connector
from mysql.connector import Error
HOST = "localhost"
PORT = 3306
USER = "sud0077"
PASSWORD = "Admin@123"
DATABASE = "QuizzApp"
try:
mydb = mysql.connector.connect(
user=USER,
password=PASSWORD,
host=HOST,
port=PORT,
database=DATABASE
)
if mydb.is_connected():
print("Connection successful")
except Error as e:
print(f"Error: {e}")
finally:
try:
if mydb.is_connected():
mydb.close()
print("Connection closed")
except NameError:
print("Connection was never established")
for more details I have shared i video link it will gives you clear picture that I am facing
youtu.be/3vFn4vrDJEM
Please help to clear this issue, I don't know how this will solve
Subject
Written By
Posted
Why I am unable to create connection with MySQL using python on Window 11 OS
January 04, 2025 03:04AM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.