• 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

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

    生命不息,学习不止。

  • 相关阅读:
    java基础问题1
    基本数据类型,string类型的瞎扯,final喜欢干的事儿。final string
    关于区块链不懂的东西
    需求更新表属性
    用户体验——响应时间
    后台运行任务nohup xxxxxx &
    jenkins打包maven工程发现有些包下载不下来
    jenkins复选框插件Extended Choice Parameter plugin
    jmeter上传文件tips
    airflow 简介
  • 原文地址:https://www.cnblogs.com/todoit/p/2595777.html
Copyright © 2020-2023  润新知