zoukankan      html  css  js  c++  java
  • R基础学习(一)-- 连接mysql数据库

    测试环境:win10+RStudio

    (1)在Console加载两个插件

    >install.packages('DBI')

    Installing package into ‘C:/Users/lmei/Documents/R/win-library/3.5’
    (as ‘lib’ is unspecified)
    trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/DBI_1.0.0.zip'
    Content type 'application/zip' length 884354 bytes (863 KB)
    downloaded 863 KB

    package ‘DBI’ successfully unpacked and MD5 sums checked

    The downloaded binary packages are in
    C:UserslmeiAppDataLocalTempRtmp6Fwdfkdownloaded_packages

    >install.packages('RMySQL')
    Installing package into ‘C:/Users/lmei/Documents/R/win-library/3.5’
    (as ‘lib’ is unspecified)trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/RMySQL_0.10.15.zip'Content type 'application/zip' length 2371644 bytes (2.3 MB)downloaded 2.3 MB
    package ‘RMySQL’ successfully unpacked and MD5 sums checked
    
    The downloaded binary packages are in
        C:UserslmeiAppDataLocalTempRtmp6Fwdfkdownloaded_packages

    (2)编写R测试脚本ConnectMySQL.R,然后点击RUN

    library(RMySQL)
    conn <- dbConnect(MySQL(), dbname = "test", username="root", password="123456",client.flag=CLIENT_MULTI_STATEMENTS)
    users = dbGetQuery(conn, "SELECT * FROM tb_user")
    dbDisconnect(conn)
    print(users)

    Console输出

    > library(RMySQL)
    > conn <- dbConnect(MySQL(), dbname = "test", username="root", password="123456",client.flag=CLIENT_MULTI_STATEMENTS)
    > users = dbGetQuery(conn, "SELECT * FROM tb_user")
    > dbDisconnect(conn)
    [1] TRUE
    > print(users)
      id name
    1  1  Tom

    mysql连接读取成功!

  • 相关阅读:
    C# 比较多个数组(lambda,匿名比较器)
    JPA javax.persistence.TransactionRequiredException
    JPA:identifier of an instance of was altered from
    JPA 连表查询
    java json转换(二)
    java querydsl使用
    SpringCloud 过滤器
    Android : Resource is not a Drawable (color or path)
    springcloud 新增微服务
    序列化二叉树
  • 原文地址:https://www.cnblogs.com/lmei/p/10165132.html
Copyright © 2011-2022 走看看