Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I had been trying to install the vanilla forums on my Mac Operating system, and for this I had created a separate database and one user from the MySQL command line:

mysql> CREATE DATABASE vanilla;

Query OK, 1 row affected (0.00 sec)

mysql> create user 'vanilla_user3'@'localhost' IDENTIFIED BY 'vanilla_password';

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'vanilla_user3'@'localhost';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

And I had been trying to connect using the below code: 

$con=mysqli_connect("localhost","vanilla_user3","vanilla_password","vanilla");

if (mysqli_connect_errno($con)) {

  echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

but unfortunately, I am getting the below error mentioned:

Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/kramer65/Sites/vanilla/info.php on line 3 Failed to connect to MySQL: No such file or directory

Can anyone tell me where I am doing wrong ? 

1 Answer

0 votes
by (12.7k points)

The issue is that the host should not be localhost, but 127.0.0.1. I ever thought localhost and 127.0.0.1 were the same, but it turned out to be different ones.

So maybe as a suggestion for future users, always use the ip when in doubt.

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.

For more information visit :

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...