pip install pymysql
    
    import pymysql
    conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql')
    cur = conn.cursor()
    cur.execute("USE scraping")
    cur.execute("SELECT * FROM page WHERE id = 1")
    print(cur.fetchone())
    # print(cur.rowcount)
    # cur.execute("INSERT INTO .......")
    # conn.commit()
    # print(cur.lastrowid)
    cur.close()
    conn.close()
    

    参考:《Python网络数据采集》