Try rmysql to read MySQL database

Source: Internet
Author: User

Rmysql has just been difficult to install in windows. For details, see

How to install rmysql in Windows

I can't wait to test it.

References: http://www.biosino.org/R/R-doc/R-data_cn/DBI-_002f-RMySQL.html

 

1. Connect to the database

> Library (rmysql) # load package> con <-dbconnect (dbdriver ("MySQL"), dbname = "eswp", user = "root", password = "root ") # To connect to the database, you must enter the user name and password through user and password. Otherwise, the database cannot be connected.

2. List tables and databases

 dbListTables(con) [1] "2008yearnew"                  "agent"                        "artifact"                     [4] "cancer_data"                  "chinese_drug"                 "conceptnum"  

3. read Table

> Dbreadtable (con, "foreign_drug") [,] # too much data, read only part of the URL register_no3 http://app1.sfda.gov.cn/datasearch/face3/content.jsp? Tableid = 36 & tablename = table36 & tableview = ???? & Id = 10987 h201201974 http://app1.sfda.gov.cn/datasearch/face3/content.jsp? Tableid = 36 & tablename = table36 & tableview = ???? & Id = 10990 h201201965 http://app1.sfda.gov.cn/datasearch/face3/content.jsp? Tableid = 36 & tablename = table36 & tableview = ???? & Id = 10984 h201201816 http://app1.sfda.gov.cn/datasearch/face3/content.jsp? Tableid = 36 & tablename = table36 & tableview = ???? & Id = 10993 h201201847 http://app1.sfda.gov.cn/datasearch/face3/content.jsp? Tableid = 36 & tablename = table36 & tableview = ???? & Amp; id = 10978 h20120182

4. query a table

> dbGetQuery(con, paste("select URL,register_no from foreign_drug where register_no ='H20120197' or register_no ='H20120196'"))                                                                                                        URL register_no1 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10987   H201201972 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10990   H20120196

5. Delete tables and disconnect

> dbRemoveTable(con, "foreign_drug")[1] TRUE> dbDisconnect(con)[1] TRUE

 

Go back first, and study tomorrow.

Life is endless, learning is endless.

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.