[英]ModuleNotFoundError: No module named 'mysql'12
I am running the following code but expected to get the records from the student table in test database.我正在运行以下代码,但希望从测试数据库中的学生表中获取记录。
Here is my code:这是我的代码:
import mysql.connector
word = input("Enter a word in English and press Enter: ")
con = mysql.connector.connect(
user="root",
password = "root",
host="localhost",
database = "test"
)
cursor = con.cursor()
query = cursor.execute("SELECT * FROM student")
results = cursor.fetchall()
if results:
for result in results:
print(result[1])
else:
print("We couldn't find any results about that.")
And here is the result:结果如下:
Traceback (most recent call last):
File "g:/python learning/mysqlconnector.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
try to use the command尝试使用命令
pip install mysql-connector
in terminal or cmd()在终端或 cmd()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.