-1

When i am using mysql.connector library to connect mysql local database with my python programme and when i am running it there is no out in my shell .What should i do please help.

This my code:

import mysql.connector

# Establish the connection
connection = mysql.connector.connect(
    host="localhost",
    user=`your text`"root",
    password="password"
)

# Check if the connection was successful
if connection.is_connected():
    print("Connection to MySQL DB successful")
else:
    print("Connection failed")

# Close the connection
connection.close()

OUTPUT:

=========== RESTART: C:\user\main.py ===========

=========== RESTART: Shell ======================
  • mysql version:8.0.40
  • python version:3.13.0
  • os : windows 10

i tried to run programme and there was no output.

4

2 Answers 2

5
import mysql.connector

mydb = mysql.connector.connect(

  host="localhost",user="root",passwd="root",use_pure=True

)

print(mydb)

I was facing similar issue. Just add use_pure=True to mysql connection properties.

Credits to this thread Python mysql-connector hangs indefinitely when connecting to remote mysql via SSH

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
2

The following is an edited version of what I wrote nearly 7 years ago for Python shell getting restarted, without any response from the questioner.


I don't know of any issue on the https://github.com/python/cpytho/issues tracker about the IDLE shell restarting when it should not (when the debugger is not is use).

It appears that you started IDLE, edited C:\user\main.py, and ran it by either hitting F5 or clicking the menu entry. As is normal, IDLE started to execute your code in a new user code process, separate from the IDLE interface process. At some point, mysql crashed the user process. When the IDLE process loses communication with the user process, it restarts the interactive Shell. This is intentional.

If IDLE is installed and functioning correctly, the only other way to see the RESTART: Shell line is to explicitly select Restart Shell from the Shell menu.

To determine whether or not your IDLE installation is the problem, run your code from the command line without involving IDLE. For example, enter py C:\user\main.py in a Command Prompt window.

I am also curious whether starting IDLE instead with py -3.13 -m idlelib -n makes any difference, even by printing an error message in CommandPrompt.


Perhaps I should have IDLE print an explanation about crashing the user process before restarting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.