pip install MySQL-python python import MySQLdb python host = 'localhost' user = 'root' password = 'password' database = 'testdb' db = MySQLdb.connect(host=host, user=user, passwd=password, db=database) python cursor = db.cursor() python query = "SELECT name, salary FROM employees" cursor.execute(query) python results = cursor.fetchall() python for row in results: name = row[0] salary = row[1] print(f"Name: {name}, Salary: {salary}") python db.close()


上一篇:
下一篇:
切换中文