1、安装pymysql包 pip install pymysql 注: MySQLdb只支持python2,pymysql支持python3 2、连接数据 import pymysql import pandas as pd from pandas import DataFrame as df conn = pymysql.Connect( host = 'IP地址', port = 端口号, user = '用户名', passwd = '用户密码', db = '数据库名称', charset = 'utf8' ) 注: 查看本机IP地址:cmd输