在 Anacondas环境中,conda install pymssql ,一直报包冲突,所以采用先在
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy 中下载 pymssql轮子,拷到E盘根目录下,采用 pip install pymssql.....whl,
在spyder环境下编写如下代码并运行:
import pandas as pd
import numpy as np import pymssql
conn = pymssql.connect(host='127.0.0.1', user='sa', password='123', database='waoswkk')
df = pd.read_sql("select * from wkkHz",con=conn)
print(df)
打印出了表的所有记录数据
读取MySql数据。
按 Ctrl+C 复制代码
import MySQLdb import pandas as pd conn = MySQLdb.connect(host = host,port = port,user = username,passwd = password,db = db_name) df = pd.read_sql('select * from table_name',con=conn) conn.close()
按 Ctrl+C 复制代码
读取SqlServer数据
1 import pymssql
2
3 conn = pymssql.connect(host=host, port=port ,user=username, password=password, database=database)
4 df = pd.read_sql("select * from table_name",con=conn)
5 conn.close()