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.
for more details I have shared i video link it will gives you clear picture that I am facing
form my end I tried everny possible scenario to fixe this, but in last NO LUCK slightly_frowning_face
Please help to clear this issue, I dont know how this will solve
Here comes an interesting part:
After debugging we found out that the program terminates at
mydb = mysql.connector.connect(
user=USER,
password=PASSWORD,
host=HOST,
port=PORT,
database=DATABASE
Good. That’s ruled out bad credentials, and an obvious connection error then (a less obvious connection error is still possible).
Maybe it is a bug. You’re both very welcome to raise that with the project team. I can’t quite figure out how that should be done, but this link is on the project page: https://bugs.mysql.com/
Networking issues can be particularly tricky, but there must be hundreds if not thousands of people out there, who can connect to MySQL from Python successfully.
It would be much better for you guys to reproduce a way to connect to MySQL that actually works for someone else (than it would for myself or others trying to reproduce something that may or may not be a bug, or that may instead be something you’re doing wrong, or have not done correctly).
There’s nothing wrong with picking the most popular choice, or anything that’s more tried and tested. Especially when running into issues with something else.
With all respect to their devs, I highly recommend you drop mysql.connector entirely, and do what Django recommends for MySQL users, and use this instead: