引用 mysql

MySQL是一种流行的关系型数据库管理系统,许多Web应用程序和网站都使用MySQL。在使用MySQL时,我们经常需要在自己的代码中引用MySQL相关的库,以便在程序中进行操作。

import mysql.connector 1. 连接MySQL数据库 mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase" ) 1. 查询表中所有数据 mycursor = mydb.cursor() mycursor.execute("SELECT * FROM customers") myresult = mycursor.fetchall() for x in myresult: print(x)