这是一段简单的连Mysql数据库的代码,供参考
- # !/usr/bin/env python
- # _*_ coding:utf-8 _*_
- # time: 2023/11/20 13:42
- # author: Gavin Tan
- import pymysql
- config = {'host':'localhost',
- 'port':3306,
- 'user':'username',
- 'password':'password',
- 'db':'Demo',
- 'charset':'utf8',
- 'autocommit':True
- }
- db = pymysql.connect(**config)
- cursor = db.cursor()
- cursor.execute('select * from startlinks LIMIT 5,10;')
- li = cursor.fetchall()
- for item in li:
- print(item)
- # cursor.execute('insert into test values(sysdate)')
- cursor.close()
- db.close()
复制代码 |