R ODBC MySQL Connection Example

前端 未结 1 931
一生所求
一生所求 2021-02-11 08:19

I\'m trying to use RODBC to connect to a MySQL db on my computer (I\'m assuming it\'s localhost). I\'ve read the package reference manual and can\'t figure out how to do anythi

相关标签:
1条回答
  • 2021-02-11 08:59

    First set up a connection.

    1) For me I had to download a driver on MySql's website, which will vary by system and version, I used this page:

    Windows ODBC Drivers

    2) Once this is downloaded run the setup utility.

    3) Next setup up the DSN. Instructions for windows are here: MySQL ODBC DSN Setup

    4) Important: Remember the name of the DSN as it is used when you create the channel in RODBC to connect to your database.

    5) Finally, once this is setup you install and load the RODBC package.

    6) To connect to your database use something like this:

    channel <- odbcConnect("mysql 2", uid="root")
    

    where 'mysql 2' is the name of your DSN connection, NOT the name of the database.

    7) Finally you can send a query like this:

    result1 <- sqlQuery(channel, paste("SELECT * from db1"))
    
    0 讨论(0)
提交回复
热议问题