Erlo

使用Pycharm操作MySql数据库

2019-10-23 13:00:44 发布   303 浏览  
页面报错/反馈
收藏 点赞

安装PyMySql模板

  pip install pymysql

配置MySQL连接参数

  pymysql.Connect()

    host、post、user、passwd、db、charset

获取cursor()对象

  cursor()

执行MySql语句

  cursor().execute()

  cursor().commit()

具体代码:

# -- coding: utf-8 --
import pymysql

def load_all_from_mysql():
    connect = pymysql.Connect(
        host = localhost,
        port = 3306,
        user = root,
        password = ******,
        db = 数据库名,
        charset = utf8
    )
    cursor = connect.cursor()
    sql = "SELECT * from 表名"
    cursor.execute(sql)
    # print(cursor.fetchall())
    for row in cursor.fetchall():
        print(row)

load_all_from_mysql()

 

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认