zoukankan      html  css  js  c++  java
  • RMySQL读取mysql数据库的尝试

    刚刚很艰难的在windows下安装上RMySQL,详见

    RMySQL在windows下的安装方法

    迫不及待的测试了一下

    参考资料:http://www.biosino.org/R/R-doc/R-data_cn/DBI-_002f-RMySQL.html

    1、连接数据库

    > library(RMySQL) #加载包
    > con <- dbConnect(dbDriver("MySQL"), dbname = "eswp", user="root", password="root")
      #连接数据库,必须通过user和password输入用户名和密码,不然连不上

    2、列出表中数据库

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

    3、读取table

    > dbReadTable(con, "foreign_drug")[3:7,1:2]#数据太多,只读取一部分
                                                                                                            URL register_no
    3 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10987   H20120197
    4 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10990   H20120196
    5 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10984   H20120181
    6 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10993   H20120184
    7 http://app1.sfda.gov.cn/datasearch/face3/content.jsp?tableId=36&tableName=TABLE36&tableView=????&Id=10978   H20120182

    4、查询table

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

    5、删除表,断开连接

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

    先回去了,明天接着学习。

    生命不息,学习不止。

  • 相关阅读:
    reverse的一些做题教训&&trick
    reverse的一些常用资料
    [攻防世界
    JavaScript 常用函数 通用函数
    宝塔突然出现Internal Server Error
    centos7上用nginx部署前后端分离项目
    postgres 如何把多行数据,合并一行,返回json字符串
    文艺平衡树
    FHQ Treap 板子
    Java后台开发有哪些提升效率的插件?
  • 原文地址:https://www.cnblogs.com/todoit/p/2595777.html
Copyright © 2011-2022 走看看