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()
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.