0

I am trying to connect to SQL database located in the same directory as in my app.R file but I get the following error if I try to connect.

con <- dbConnect(RMySQL::MySQL(), dbname = "super_data") 

Error in .local(drv, ...) : Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)

mydb = dbConnect(MySQL(), user='root', password='', dbname='super_data.sql', host='localhost') 

Error in .local(drv, ...) : Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)

1 Answer 1

1

Try with the following code:

conn <- RMySQL::dbConnect(RMySQL::MySQL(), user = "root", password = "mypassword", dbname = "mydatabase", host = "127.0.0.1", # Instead of localhost port = 3306) # Default MySQL port 

Hope this can help

Sign up to request clarification or add additional context in comments.

1 Comment

It is just a .sql file lying in the same directory do I need to host it somewhere before running this line?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.