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

0 votes

I'm trying to install vanilla forums on my Mac, and for this I just created a database and a 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)

So I try to connect using the following 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 get an error saying

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

Any idea where I'm going wrong?

Nov 6, 2020 in PHP by kartik
• 37,520 points
18,338 views

1 answer to this question.

0 votes

Hello @kartik,

edit these two lines in /etc/php.ini (or wherever your php.ini is located):

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Restart apache server to make sure the changes are reflected.

sudo apachectl restart

Hope it helps!!

Thank You!!

answered Nov 6, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
0 answers

PHP - Failed to open stream : No such file or directory

In PHP scripts, when I call include(), require(), fopen(), or ...READ MORE

May 16, 2022 in PHP by Kichu
• 19,040 points
7,094 views
0 votes
1 answer

Error:Failed to open stream : No such file or directory.

Hello @kartik, Go to the file to include ...READ MORE

answered Oct 1, 2020 in PHP by Niroj
• 82,840 points
37,061 views
0 votes
0 answers
0 votes
1 answer

How can I connect to MySQL in Python 3 on Windows?

Hello @kartik, You should probably use pymysql - Pure Python ...READ MORE

answered Aug 20, 2020 in PHP by Niroj
• 82,840 points
946 views
+1 vote
1 answer

How to migrate a PostgreSQL database into a SQLServer one?

Hello @kartik, The easier way to accomplish this. First ...READ MORE

answered May 13, 2020 in Database by Niroj
• 82,840 points
990 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,682 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,442 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,840 points
1,220 views
0 votes
1 answer

Error:PDOException SQLSTATE[HY000] [2020] No such file or directory in php?

Hello, I checked php -i | grep pdo and noticed ...READ MORE

answered Apr 2, 2020 in PHP by Niroj
• 82,840 points
1,415 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP