Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@benchan

R言語でDB接続(MySQL)から取得までメモ

More than 3 years have passed since last update.

R言語でDB接続(MySQL)から取得まで

# ライブラリの読み込み 
library("RMySQL")

# RStudioの場合 packagesのパネルからチェックを入れれば自動で読み込まれる
library("RMySQL", lib.loc="/usr/local/Cellar/r/3.2.2/R.framework/Versions/3.2/Resources/library")

# MySQLドライバ
md <- dbDriver("MySQL")

# DB接続
dbconnector <- dbConnect(md, dbname="<DB名>", user="<user>", password="<password>",  host="<host>") 


# dbGetQuery、dbSendQueryの違い
# クエリ実行 結果をデータセットに保管
data <- dbGetQuery(dbconnector, "select * from sample_table")

# MySQLResult形式で保管
sqlResult <- dbSendQuery(dbconnector, "select * from sample_table")

# MySQLResultからデータセット保管
data <- fetch(sqlResult)


# 破棄する
dbDisconnect(dbconnector)


6
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
benchan
e-grant
EC・通販に特化したCRMツール「うちでのこづち」を中心に、CRM関連のビックデータ・AI系の開発・運営を行なっています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?