Access MySQL database in R studio

I want to access the database in MySQL but i am getting the following error:

can't connect to mysql server through socket /var/run/mysqld/mysqld.sock.

How do i solve this?

Can you please be more specific? What is the code you are using to connect to that particular MySQL server and where the server is hosted?

This is the code i tried but it keeps returning that error message

connection <- dbConnect(
drv = MariaDB(),
dbname = database,
user = user,
password = password,
host = host,
port = port

Do i need to do something with MySQL workbench?