python链接数据库

  1. https://blog.csdn.net/u010099177/article/details/93220251
    #首先先添加清华的镜像源
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --set show_channel_urls yes
    ————————————————
    原文链接:https://blog.csdn.net/ada0915/article/details/78529877

  2. [0x7FFA6F01C250] ANOMALY: use of REX.w is meaningless (default operand size is 64)
    一直报这个错误,目前解决不了,先记下来吧,不影响使用

import pymysql
conn = pymysql.connect(
    host='localhost',
    user='root',
    passwd='填写自己的密码',
    db='pystudy',
    port=3306,
    charset='utf8')
  1. cursor = conn.cursor()
    creat = ‘’’
    CREATE TABLE TEXT1(
    id int,
    name char(8),
    grade int
    )engine innodb default charset = utf8;’’’
    cursor.execute(creat)
    conn.commit()
  2. from pandas import DataFrame
    import pymysql
  3. conn = pymysql.connect(
    host = ‘localhost’,
    user = ‘root’,
    password = ‘986532aa’,
    db = ‘pystudy’,
    port = 3306,
    charset = ‘utf8’
    )
    cursor = conn.cursor()
    rows = cursor.execute(‘select * from ch4ex9’)
    rows
  4. import pandas as pd
    df = pd.read_sql(‘select * from ch4ex9’,conn)
    df
  5. data = cursor.fetchall()
  6. df = DataFrame(list(data))
    df
  7. df.to_sql(name=‘text1’,con=‘mysql+pymysql://root:986532aa@localhost:3306/pystudy?charset=utf8’,if_exists=‘replace’,index=False)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值