ModuleNotFoundError: No module named 'mysql'12
ModuleNotFoundError: No module named 'mysql'12
我是 运行 以下代码,但希望从测试数据库中的学生 table 获取记录。
这是我的代码:
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.")
结果如下:
Traceback (most recent call last):
File "g:/python learning/mysqlconnector.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
尝试使用命令
pip install mysql-connector
在终端或 cmd()
我是 运行 以下代码,但希望从测试数据库中的学生 table 获取记录。
这是我的代码:
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.")
结果如下:
Traceback (most recent call last):
File "g:/python learning/mysqlconnector.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
尝试使用命令
pip install mysql-connector
在终端或 cmd()