The program terminates automatically without throwin any error or output
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") 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.

if mydb.is_connected():. If it can't connect, it will raise an exception.