连接的是Mysql数据库
首先,在idea中执行命令 pip install pymysql 安装可执行的文件
文件安装完成后,一般会在项目的venv---->Lib---->site packages 下,需要将pymysql文件夹放到Lib下面
此时.py中的import pymysql不报错
我们就可以使用操作数据库的代码
import pymysql
db =pymysql.connect( port=3306,user='root',password='root',db='asso',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
cusor = db.cursor()
cusor.execute("select * from org")
for row in cusor.fetchall():
print(row)
db.close();
参数如上
打印结果:
D:\pythonOut\venv\Scripts\python.exe D:/pythonOut/casasa1.py
{'id': 1, 'orgType': '1', 'managerId': '0', 'companyCode': '10000000', 'name': '总公司', 'alias': '北京', 'postAddress': None, 'postCode': None, 'phoneNumber': None, 'mobile': None, 'email': None, 'faxNumber': None, 'personId': None, 'comCode': '10000000', 'businessNature': None, 'orgCode': None, 'customerCode': None, 'agentCode': None, 'proId': None, 'isBalance': None, 'balanceFlag': None, 'payFlag': None, 'coinsFlag': None, 'coinsRate_gb': None, 'coinsRate_lb': None, 'customerType': None, 'sellerId': None, 'handlerId': None, 'handler1Id': None, 'approverId': None, 'operatorId': None, 'generateMethod': None, 'status': '1', 'isParent': 'true', 'iconSkin': 'pIcon01', 'createId': None, 'delId': None, 'creatTime': None, 'updateTime': None, 'conment': None, 'spare01': None, 'spare02': None, 'spare03': None, 'spare04': None}
{'id': 2, 'orgType': '2', 'managerId': '0', 'companyCode': '10000000', 'name': '总公司外部客户', 'alias': '北京', 'postAddress': None, 'postCode': None, 'phoneNumber': None, 'mobile': None, 'email': None, 'faxNumber': None, 'personId': None, 'comCode': '10000000', 'businessNature': None, 'orgCode': None, 'customerCode': None, 'agentCode': None, 'proId': None, 'isBalance': None, 'balanceFlag': None, 'payFlag': None, 'coinsFlag': None, 'coinsRate_gb': None, 'coinsRate_lb': None, 'customerType': None, 'sellerId': None, 'handlerId': None, 'handler1Id': None, 'approverId': None, 'operatorId': None, 'generateMethod': None, 'status': '1', 'isParent': 'true', 'iconSkin': 'pIcon01', 'createId': None, 'delId': None, 'creatTime': None, 'updateTime': None, 'conment': None, 'spare01': None, 'spare02': None, 'spare03': None, 'spare04': None}
{'id': 40, 'orgType': '1', 'managerId': '1', 'companyCode': '44000000', 'name': '广东省分公司', 'alias': '广东省分公司', 'postAddress': '', 'postCode': None, 'phoneNumber': '135', 'mobile': '', 'email': '', 'faxNumber': '', 'personId': '', 'comCode': '44000000', 'businessNature': '1', 'orgCode': None, 'customerCode': None, 'agentCode': None, 'proId': '', 'isBalance': None, 'balanceFlag': None, 'payFlag': None, 'coinsFlag': None, 'coinsRate_gb': None, 'coinsRate_lb': None, 'customerType': None, 'sellerId': None, 'handlerId': None, 'handler1Id': None, 'approverId': None, 'operatorId': None, 'generateMethod': None, 'status': '1', 'isParent': 'true', 'iconSkin': 'pIcon01', 'createId': '1', 'delId': '', 'creatTime': datetime.datetime(2017, 8, 4, 0, 0), 'updateTime': datetime.datetime(2017, 8, 21, 0, 0), 'conment': None, 'spare01': None, 'spare02': None, 'spare03': None, 'spare04': None}
{'id': 41, 'orgType': '2', 'managerId': '2', 'companyCode': '44000000', 'name': '广东省分公司外部客户', 'alias': '广东省分公司', 'postAddress': '', 'postCode': None, 'phoneNumber': '', 'mobile': '', 'email': '', 'faxNumber': '', 'personId': '', 'comCode': '44000000', 'businessNature': '1', 'orgCode': None, 'customerCode': None, 'agentCode': None, 'proId': '', 'isBalance': None, 'balanceFlag': None, 'payFlag': None, 'coinsFlag': None, 'coinsRate_gb': None, 'coinsRate_lb': None, 'customerType': None, 'sellerId': None, 'handlerId': None, 'handler1Id': None, 'approverId': None, 'operatorId': None, 'generateMethod': None, 'status': '1', 'isParent': 'true', 'iconSkin': 'pIcon01', 'createId': '1', 'delId': '', 'creatTime': datetime.datetime(2017, 8, 4, 0, 0), 'updateTime': datetime.datetime(2017, 8, 4, 0, 0), 'conment': None, 'spare01': None, 'spare02': None, 'spare03': None, 'spare04': None}