美文网首页python热爱者
Python3.5连接Mysql

Python3.5连接Mysql

作者: Clemente | 来源:发表于2017-12-18 16:02 被阅读11次

    由于mysqldb目前仅支持到python3.4,所以这里选择pymysql。

    pymysql下载地址:

    [https://pypi.python.org/packages/source/P/PyMySQL3/PyMySQL3-0.5.tar.gz]

    解压之后,运行cmd,切换到PyMySQL3-0.5目录


    image.png

    输入python setup.py install,执行安装


    image.png image.png

    安装完了,测试一下
    在py程序中引用 pymysql

    import pymysql
    

    执行代码,如果没有报错的话就表示 pymysql安装成功了
    接着

    import pymysql
    conn = pymysql.connect(user='root',passwd='root',host='localhost',db='school')
    或
    db = pymysql.connect("localhost","root","root","school" )
    cursor = conn.cursor()
    cursor.execute("select * from yingxiong")
    row_100 = cursor.fetchmany(12)
    print(row_100)
    conn.commit()
    cursor.close()
    

    相关文章

      网友评论

        本文标题:Python3.5连接Mysql

        本文链接:https://www.haomeiwen.com/subject/hismwxtx.html