R language reading MySQL data sheet

Source: Internet
Author: User
Tags comments odbc mysql odbc driver

Installing the RODBC package in 1.R

Install.packages ("RODBC")

2. Installing MySQL ODBC in Windows system Drive

Note distinguish between 32-bit and 64-bit versions;

Http://dev.mysql.com/downloads/connector/odbc

System configuration for 3.ODBC

Under Windows operating system: Control Panel, administrative Tools, data source (ODBC), double-click Add, select MySQL ODBC driver

Fill in: Data source name an entry you want to use the name, you name it, for example: Mysql_data;

Description A random fill, such as MyData

TCP/IP Server fills out the MySQL database with the address, such as: 127.0.0.1

User fills in your MySQL username

Password fill in your MySQL password

The database will then appear in your MySQL database, select a database.


4. Turn on the R environment test

#R代码 查询示例library(RODBC)channel<-odbcConnect("mysql_data", uid="baidu_index", pwd="******"# 64 位ODBC,****替换为输入密码sqlKeyword = "SELECT * FROM BAIDU_INDEX WHERE col_keyword = ‘李易峰‘ AND col_date>=‘2015-01-01‘"dataKeyword=sqlQuery(channel,sqlKeyword)keywordList<-dataKeyword[["col_keyword"]]keywordList<-as.character(keywordList)

5. Rodbc other functions for working with MySQL database

# 函数名称 # 函数描述odbcConnect(dsn, uid="", pwd="")   # 建立并打开连接 sqlFetch(channel, sqltable)  # 从数据库读取数据表,并返回一个数据框对象sqlQuery(channel, query)   # 向数据库提交一个查询,并返回结果sqlSave(channel, mydf, tablename = sqtable, append = FALSE)  # 将一个数据框写入或更新(append=True)到数据库sqlDrop(channel, sqtable)  # 从数据库删除一个表sqlClear(channel, sqtable)   # 删除表中的内容sqlTables(channel)  # 返回数据库中表的信息sqlColumns(channel, sqtable)  # 返回数据库表sqtable列的信息close(channel)  # 关闭连接

R language reading MySQL data sheet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.