Python连接数据库
本人python3.5
1.安装
pip3 install mysql-connetor
2.测试(打开python.exe)
3.代码测试
#coding:utf-8 import pymysql conn = pymysql.connect( host = 'localhost', port = 3306, user = 'root', passwd = 'mysql', db = 'cltest' ) cur = conn.cursor() sql = "select id,status from cost_cl where id in (1,2)" cur.execute(sql) rows = cur.fetchall() for dr in rows: print(dr)
结果