Help fixing MySQL connection

Job ID: 34922559

Budget: $10 – $30 USD

I need someone to tell me how to create the appropriate user to be able to connect to mysql.
I have a file called db.inc which is located in the includes directory/folder.

<?php
$dbuser = "user1";
$dbpwd = "password";
try {
$dbh = new PDO('mysql:host=domain.com;dbname=domain', $dbuser, $dbpwd);
}
catch( PDOException $Exception) {
$exccode = $Exception->getCode();
$excmsg = $Exception->getMessage();
}
if (!empty($exccode)) {
die($exccode." - ".$excmsg."<br>\n");
}
?>

I have also run the following SQL command:

# mysql
mysql> CREATE USER 'user1'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost' WITH GRANT OPTION;
mysql> exit

Currently I am getting the error "2002 - SQLSTATE[HY000] [2002] Connection refused" and I am unable to figure out why I am getting this error.

Can someone explain what needs to be done to make this work?

I know this is a small issue for someone who works with LAMP servers and MySQL every day.
Related categories: PHP Linux SQL MySQL LAMP