chmod a+rw /usr/local/lib/R/site-librarymysql
$ Rlinux
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)sql
R是自由軟件,不帶任何擔保。
在某些條件下你能夠將其自由散佈。
用'license()'或'licence()'來看散佈的詳細條件。數據庫
R是個合做計劃,有許多人爲之作出了貢獻.
用'contributors()'來看合做者的詳細狀況
用'citation()'會告訴你如何在出版物中正確地引用R或R程序包。瀏覽器
用'demo()'來看一些示範程序,用'help()'來閱讀在線幫助文件,或
用'help.start()'經過HTML瀏覽器來看幫助文件。
用'q()'退出R.post
> install.packages("RMySQL")
【postgresql用install.packages("RPostgreSQL")】postgresql
R腳本tmysql.rcode
#!/usr/bin/env Rscript library(RMySQL) #help(package=」RMySQL」) 查看RMySQL的說明文檔,裏面有RMySQL全部可用的方法 #建立數據庫鏈接 con <- dbConnect(MySQL(),host="localhost",dbname="y-db",user="y-user",password="y-passwd") #獲取鏈接信息,查看database下全部表,以及查看y-table表 dbSendQuery(con,'SET NAMES utf8') dbListTables(con) dbReadTable(con,"y-table")
腳本tpsql.rorm
#!/usr/bin/env Rscript library(RPostgreSQL) #help(package=」RPostgreSQL」) 查看RPostgreSQL的說明文檔,裏面有RPostgreSQL全部可用的方法 #建立數據庫鏈接 con <- dbConnect(PostgreSQL(),host="localhost",dbname="y-db",user="y-user",password="y-passwd") #獲取鏈接信息,查看y-db下全部表,已經訪問表y-table dbListTables(con) dbReadTable(con,"y-table")
chmod a+x tpsql.r tmysql.r後即可執行上述R腳本程序ip