数据库操作
使用pymysql 模块可以对数据库进行链接 操作。
https://pypi.org/project/PyMySQL/
安装
pip install pymysql
连接数据库
数据库连接信息
主机地址:49.233.108.117
端口号:3306
用户名:root
密码:fanmao888
数据库:mall
使用python的方式进行数据库连接。
# 导入模块
import pymysql
# 连接数据库
connections = pymysql.connect(
host='49.233.108.117',
port=3306,
user='root',
password='fanmao888',
database='mall'
)
with connections.cursor() as cursor:
# 编写查询语句
sql = "select * from tb_newbee_mall_user;"
cursor.execute(sql)
# 查看一条结果
# result = cursor.fetchone()
# 查看所有的结果
result2 = cursor.fetchmany()
# print(result)
print(result2)