gpt4 book ai didi

mysql - 连接 MySQL 和 R

转载 作者:搜寻专家 更新时间:2023-10-30 20:47:45 25 4
gpt4 key购买 nike

这就是我尝试将 MySQL 连接到 R 的方式。

db <- dbConnect(MySQL(), user='username', password='pwd',dbname=dbx, host = 'local', port = 3306)

但是我收到了这个错误:

Error in .local(drv, ...) : Failed to connect to database: Error: Plugin caching_sha2_password could not be loaded: The specified module could not be found.

怎么办?

最佳答案

您可以创建一个函数来检索查询。

library(RMySQL)
sqlQuery <- function (query) {

# creating DB connection object with RMysql package
DB <- dbConnect(MySQL(), user="user", password="password",
dbname="databaseName", host="host")

# close db connection after function call exits
on.exit(dbDisconnect(DB))

# send Query to obtain result set
rs <- dbSendQuery(DB, query)

# get elements from result sets and convert to dataframe
result <- fetch(rs, -1)

# return the dataframe
return(result)
}

然后就是:

new_dataframe <- sqlQuery("SELECT * from table")

希望对你有帮助

关于mysql - 连接 MySQL 和 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52811149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com