R学习笔记——RMySQL使用

1、初次使用

con <- dbConnect(MySQL(), user = 'root', password = '144230', dbname = 'test', host='localhost')
错误于mysqlNewConnection(drv, ...) :
  RS-DBI driver: (Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
)
无语:又报错


2、网上说需要先安装 mysql-workbench 试试能否正常连接

当然先安装 MySQL,这个我以前写过,接下来安装 mysql-workbench,mysql-workbench 需要先安装 mysql-share,下载的文件如下

[root@localhost mysql]# ls
MySQL-shared-compat-5.6.16-1.linux_glibc2.5.i386.rpm
mysql-workbench-community-6.0.9-1.el6.i686.rpm

//然后安装: 
[root@localhost mysql]# rmp -ivh MySQL-shared-compat-5.6.16-1.linux_glibc2.5.i386.rpm
[root@localhost mysql]# rmp -ivh mysql-workbench-community-6.0.9-1.el6.i686.rpm 
搞定,可以正常连接:


6、可是我的 RMySQL 还是连不上。怎么办? 查看基本信息

> dbConnect(m, user = "root", password = "144230", dbname = "test", host="localhost.localdomain")
 
> m <- MySQL()
> m
 
> dbConnect(m, user = "root", password = "144230", dbname = "test")
错误于mysqlNewConnection(drv, ...) : 
  RS-DBI driver: (Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
)
> Sys.info()
                              sysname                               release 
                              "Linux"                 "2.6.32-358.el6.i686" 
                              version                              nodename 
"#1 SMP Thu Feb 21 21:50:49 UTC 2013"               "localhost.localdomain" 
                              machine                                 login 
                               "i686"                              "clebeg" 
                                 user                        effective_user 
                             "clebeg"                              "clebeg" 
哦,原来它识别不了默认的 host

接下来用下面语句链接:

> dbConnect(m, user = "root", password = "144230", dbname = "test", host="localhost.localdomain")
 

> conn <- dbConnect(m, user = "root", password = "144230", dbname = "test", host="localhost.localdomain")
> table.names = dbListTables(con) 
> table.names
[1] "t_user"

你可能感兴趣的:(R,语言学习)