This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import pymysql
def connect_db():
# 数据库连接参数
db_host = 'localhost' # 数据库主机名
db_user = 'root' # 数据库用户名
db_password = '123456' # 数据库密码
db_database = 'user_info' # 数据库名
db_port = 3306 # 数据库端口,通常默认为3306
# 创建连接
connection = pymysql.connect(host=db_host,
user=db_user,
password=db_password,
database=db_database,
port=db_port)
cursor = connection.cursor()
return cursor
if __name__ == '__main__':
cursor = connect_db()
print("数据库连接成功!")