在继续之前,请确保已在计算机上安装了MySQLdb。只需在Python脚本中键入以下内容并执行-
#!/usr/bin/python import MySQLdb
如果产生以下结果,则表示未安装MySQLdb模块-
Traceback (most recent call last): File "test.py", line 3, in <module> import MySQLdb ImportError: No module named MySQLdb
要安装MySQLdb模块,请使用以下命令-
For Ubuntu, use the following command - $ sudo apt-get install python-pip python-dev libmysqlclient-dev For Fedora, use the following command - $ sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc For Python command prompt, use the following command - pip install MySQL-python
注意-确保您具有root特权才能安装上述模块。