当前位置:   article > 正文

python连接数据库_python连接doris

python连接doris

1、导入数据库模块

import pymysql

2、连接数据库

conn=pymysql.connect(host="填写数据库ip",
                user="填写数据库用户名",  
                passwd="填写数据库用户密码",
                db="填写数据库名",
                port=端口号(一般是3306),
                charset="utf8",
                autocommit=True #此参数代表自动提交,如不写则需单独执行commit()命令
                     )
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3、建立游标

cursor=conn.cursor(pymysql.cursors.DictCursor)
  • 1

4、执行sql语句

#show tables;查看当前所有表
#cursor.execute("show tables;")
#cursor.execute('insert into students (name,phone,age,sex) values ("wxy",18500979583,18,"女");')
cursor.execute("select * from students limit 5")
  • 1
  • 2
  • 3
  • 4

5、取数据库字段信息

print(cursor.description)
</
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/973197
推荐阅读
相关标签
  

闽ICP备14008679号