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

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

    生命不息,学习不止。

  • 相关阅读:
    Unity3D之如何将包大小减少到极致
    3DMAX 如何将删去的面补回来
    3DMAX 7 角色建模1 人头建模
    Unity json
    unity资源管理
    unity 引入 android第三方sdk
    unity调用Android的jar包
    Unity3D游戏开发之Unity与Android交互调用研究
    unity3d easytouch教程
    Unity手游之路游戏摇杆之Easy Touch 3教程
  • 原文地址:https://www.cnblogs.com/todoit/p/2595777.html
Copyright © 2011-2022 走看看