2016-11-13 109 views
1

我正在学习如何在R中的包RMySQL使用MySQL:无法连接到本地MySQL服务器中的R

https://www.tutorialspoint.com/r/r_database.htm

但是当我尝试连接到在例如

提供的DB
mysqlconnection = dbConnect(MySQL(), user = 'root', password = '', dbname = 'sakila', host = 'localhost') 

我得到:

Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 

我的猜测是,我运行它只是在我的LAPT op(mac os),所以如果我的猜测是正确的(?),我需要一些虚拟服务器。

你知道有这样做的R包吗?任何建议表示赞赏。

回答

2

首先检查你的SQL服务正在运行。

服务mysqld的启动

然后尝试的mysql -u根

如果不从上述解决方案解决问题,尝试用主机=“127.0.0.1”,而不是本地主机。因为127.0.0.1使用TCP/IP连接器。除非localhost使用套接字连接器运行。

+0

谢谢,应该在R promp中运行“service”和“mysql”命令吗? –

+0

Nop。你的操作台。 –

+0

https://coolestguidesontheplanet.com/start-stop-mysql-from-the-command-line-terminal-osx-linux/ –