python 中使用 mysql
注意:py中使用 mysql 需要提前安装 mysql 可以参考:mysql 逐步安装
安装pymysql
使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import pymysql import time
conn = pymysql.connect( host='localhost', port=3306, user='root', password='123456', database='test', charset='utf8' )
cursor = conn.cursor()
sql = 'select * from user where create_time > %s' times = time.mktime(time.strptime("2024-01-01 00:00:00","%Y-%m-%d %H:%M:%S")) cursor.execute(sql, (times, ))
result = cursor.fetchall() print(result)
cursor.close()
conn.close()
|