简体   繁体   中英

Using MySQL in Pydev Eclipse

I am trying to access a MySQL database with python through Pydev Eclipse. I have installed the necessary files to access MysQL from python and I can access the database only when I write code in Python IDLE environment and run it from command prompt. However I am not able to run my applications from Pydev.

when I use this "import MysqlDB" i get an error, but in IDLE no errors and my code runs very smoothly. Does anyone know were the problem is? Thanks

I was having this same problem and found this link which helped me resolve it. https://bohr.wlu.ca/cp363/notes/implementation/connectingPython.php

From there I was able to import mysql.connector and connect to the database installed on my localhost

import mysql.connector
import getpass

pswd = getpass.getpass(prompt='Enter database password for root user:')
dbCnx = mysql.connector.connect(user='root', password=pswd)

这是我如何执行 pip install 的屏幕截图

If the connector works in the IDLE but not in PyDev. Open Eclipse preferences, open PyDev directory and go to interpreter screen. Remove the interpreter and add it again from the location on your computer (Usually C drive). Close and reload Eclipse and now it should work.

Posting Answer in case URL changed in future

From Eclipse, choose Window / Preferences / PyDev / Interpreters / Python Interpreter, click on Manage with pip and enter the command:

install mysql-connector-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM