RMySQL

library(RMySQL)
con <-  dbConnect(RMySQL::MySQL(),
                  username = "root",
                  password = "123456",
                  host = "127.0.0.1",
                  port = 3306,
                  dbname = "python"
)


con <- DBI::dbConnect(odbc::odbc(),
                      driver = "/opt/rstudio-drivers/mysql/bin/lib/libmysqlodbc_sb64.so",
                      database = "python",
                      UID    = "root",
                      PWD    = "123456",
                      server = "172.17.0.5",
                      port = 3306)


# con <- dbConnect(odbc::odbc(), "oracledb", UID="samples",
#                  PWD= rstudioapi::askForPassword("Samples User Password"))

library(DBI)
#"MySQL"为/etc/odbc.ini配置的信息
# [MySQL]
# Driver=/opt/rstudio-drivers/mysql/bin/lib/libmysqlodbc_sb64.so
# DSN=MySQL
# Server = 172.17.0.5
# Database = python
# Port = 3306
# USER=root
# PASSWORD=123456

con <- DBI::dbConnect(odbc::odbc(), dsn="MySQL")
dbListTables(con)
dbListFields(con, "heros")
dbGetQuery(con, "SELECT * FROM heros")
data <- dbReadTable(con, "heros")
data <- dbWriteTable(con, "iris", iris)
dbDisconnect(con)



sudo apt-get install unixodbc unixodbc-devel gdebi
curl -O https://drivers.rstudio.org/7C152C12/installer/rstudio-drivers_1.6.0_amd64.deb
sudo apt-get install rstudio-drivers_1.6.0_amd64.deb
ln -s /usr/lib/oracle/19.5/client64/lib/* /opt/rstudio-drivers/oracle/bin/lib/

# Backup existing ODBC configuration file
sudo cp /etc/odbcinst.ini /etc/odbcinst.ini.bak

# Append sample ODBC configuration file into /etc/
cat /opt/rstudio-drivers/odbcinst.ini.sample | sudo tee /etc/odbcinst.ini

#
cat /etc/odbc.ini
[MySQL]
Driver=/opt/rstudio-drivers/mysql/bin/lib/libmysqlodbc_sb64.so
DSN=MySQL
Server = 172.17.0.5
Database = python
Port = 3306
USER=root
PASSWORD=123456
 
con <- DBI::dbConnect(odbc::odbc(),                       driver = "/opt/rstudio-drivers/mysql/bin/lib/libmysqlodbc_sb64.so",                       database = "python",                       UID = "root",                       PWD = "123456",                       server = "172.17.0.5",                       port = 3306)

CON < - DBI ::数据库连接(ODBC :: ODBC(),
                      驱动= “/opt/rstudio-drivers/mysql/bin/lib/libmysqlodbc_sb64.so”,
                      数据库=“蟒”,
                      UID = “根”,
                      PWD = “123456”,
                      服务器= “172.17.0.5”,
                      端口= 3306)

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理