Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

How do I connect mysql to python in pycharm. I currently use Ubuntu 20.04?

Can someone please help me connecting python to mysql. I am new to Ubuntu OS and don't know much about it. I use PyCharm IDE. I installed mysql on my system and also installed the mysql.connector module correctly( pip3 isntall mysql-connector-python ) But it fails t connect and gives the error as follows: mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported When I run the same code in VS code I get an error which reads: Traceback (most recent call last): File "/home/velocity-linux/Desktop/Main Folder/Project.py", line 1, in import mysql.connector ImportError: No module named mysql.connector Please tell what can I do The code which I use for connection is:


mydb1 = mysql.connector.connect(host="localhost", user="root",
                                passwd="home@253144", database="school")``` 


  [1]: https://i.stack.imgur.com/aGXKQ.png
question from:https://stackoverflow.com/questions/65845318/how-do-i-connect-mysql-to-python-in-pycharm-i-currently-use-ubuntu-20-04

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's likely you're getting the error in Visual Studio Code because you're using a virtual environment in PyCharm.

The PyCharm error is the error you should be focusing on.

What imports are you using for this project? The error seems to be caused by an unsupported library, I am unsure if this is from your script or a script from the mysql-connector library.

Have you tried reinstalling mysql-connector with both python -m pip uninstall mysql-connector and python -m pip install mysql-connector?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...