R和python分别连接mysql8.0及mongodb4.2数据库

1.python连接mysql8.0数据库

import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+mysqlconnector://root:123456@localhost:3306/ssm')
sql = 'select * from teacher;'
df = pd.read_sql_query(sql,engine)
print(df)

2.R连接mysql8.0数据库(自行配置ODBC)

library(RODBC) 
channel <- odbcConnect("RMySQL",uid = "root",pwd = "123456")
crimedat <- sqlQuery(channel,"select * from teacher")
print(crimedat)

3.python连接mongodb4.2数据库(本人mongo没设密码)

from pymongo import MongoClient
connect = MongoClient('mongodb://localhost:27017/')
db = connect['analysis']
collection = db['student']
collection.find_one()

4.R连接mongodb4.2数据库(本人mongo没设密码)

library(mongolite)
con <- mongo(collection = "student",db = "analysis", url = "mongodb://localhost")
con$find()

你可能感兴趣的:(python,mysql,mongodb)