Advertisement

Python关联MySQL库中的cursor,并通过pandas库访问数据,在Jupyter环境中运行

阅读量:

文章结构概览

  • Python实现与MySQL数据库的连接
      • 一、采用 mysql-connector 实现连接

        • 1. 利用cursor执行SQL指令
        • 2. 使用pandas进行数据读取
      • 二、借助 ipython-sql 与 pymysql 建立连接

        • 1. 非Jupyter运行环境
          • a. 通过游标操作数据
      • b. 应用pandas进行数据处理

        • 2. 在Jupyter环境下,使用魔法函数实现连接

Python连接MySQL实现

一、通过 mysql-connector 连接

执行以下命令以完成安装:pip install mysql-connector-python

复制代码
    import mysql.connector
    cnx = mysql.connector.connect(
    user='root', password='',
    host='127.0.0.1', database='mysql')
    
    
    AI写代码python
    
    运行

1. 用cursor使用sql语句

复制代码
    cu

全部评论 (0)

还没有任何评论哟~