import pymysql
import yaml
import flask

# 连接数据库
with open('config.yml', 'r') as file:
    config = yaml.safe_load(file)
host = config['mysql']['host']
port = config['mysql']['port']
user = config['mysql']['user']
password = config['mysql']['pass']
db = config['mysql']['db']


my_db = pymysql.connect(
    host=host,
    port=int(port),
    user=user,
    password=password,
    database=db
)

# 创建游标对象
cursor = my_db.cursor()

# 执行查询语句
cursor.execute("SELECT pub_ip FROM basic_info")

# 获取全部查询结果
result = cursor.fetchall()

# 打印查询结果
print(result)
print(type(result))
# for row in result:
#   print(row[1])

# 关闭游标和数据库连接
cursor.close()
my_db.close()
