分段错误 MySQLdb [英] Segmentation fault MySQLdb
问题描述
我已经为 python 安装了 MySQLdb,并有以下代码.
I have installed MySQLdb for python, and have the following code.
import MySQLdb
conn = MySQLdb.connect(host="hello")
每次我在终端上运行它时,我都会遇到分段错误(核心转储)
Everytime I run this on terminal, I get Segmentation fault (core dumped)
但是当我把上面几行放在 hi.py 文件中,并运行 python hi.py 时,我在终端中没有看到这个错误.
But when I put the above lines in hi.py file, and run python hi.py, then I do not see this error in terminal.
谁能给我建议来解决这个问题?
Could anyone give me an advice to fix this problem?
$ python
>>> import MySQLdb
>>> conn = MySQLdb.connect(host="hello")
Segmentation fault (core dumped)
这是我在终端中输入的命令.并得到分段错误错误.
This is the command I typed in the terminal. And got segmentation fault error.
推荐答案
我之前也遇到过类似的问题,请尝试在终端上使用 python2.
I have encountered a similar problem before, try checking if you are using python2 with the terminal.
MySQLdb 不适用于 python3.如果你想使用 python3 使用 mysql-connector-python
MySQLdb does not work with python3. If you want to work with python3 use mysql-connector-python
你可以用pip
安装:pip install mysql-connector-python
这篇关于分段错误 MySQLdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!