Warning mysql connect 2002 No such file or directory trying to connect via unix tmp mysql sock

0 votes

I'm trying to connect to my MySQL DB with the Terminal on my Apple (With PHP).

The script works when I use my browser to run it (I have XAMPP installed), but Terminal refuses to connect to the DB.

Here is the file that I include to connect (the script works when I don't include this, but then it doesn't connect to the DB):

<?php
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("FNB1C_data") or die(mysql_error());
?>

That should work, since it works with my browser.

The command I use at the Terminal is php scriptname.php.

May 4, 2020 in Database by kartik
• 37,520 points
2,657 views

1 answer to this question.

0 votes

Hii

I was having the same problem and this is how I fixed it:

I had this and it didn't work:

$con = mysql_connect('localhost', 'root', '1234');

I did this and it worked:

$con = mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', '1234');

Instead of using the mysql server, I connected directly to the Unix Socket. Worked for me.

Thank You!!

answered May 4, 2020 by Niroj
• 82,840 points

Related Questions In Database

0 votes
0 answers

PDOException SQLSTATE[HY000] [2002] No such file or directory

My (very basic) site appears to have ...READ MORE

Sep 3, 2022 in Database by Kithuzzz
• 38,000 points
2,047 views
0 votes
1 answer

How to connect to MySQL Database?

using MySql.Data; using MySql.Data.MySqlClient; namespace Data { ...READ MORE

answered Oct 12, 2018 in Database by Frankie
• 9,830 points
1,135 views
+2 votes
1 answer

How to export data from MySql to a CSV file?

If you are using MySql workbench then ...READ MORE

answered Jan 4, 2019 in Database by Priyaj
• 58,020 points
1,554 views
0 votes
1 answer

How to load data of .csv file in MySQL Database Table?

At first, put the dataset in the ...READ MORE

answered Jul 5, 2019 in Database by Reshma
1,411 views
0 votes
1 answer

Error:Import SQL dump into PostgreSQL database

Hello, Here is the command you are looking ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,840 points
5,225 views
0 votes
1 answer

MySQL Error: : 'Access denied for user 'root'@'localhost'

Hello @kartik, I did this to set my ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,840 points
18,418 views
0 votes
1 answer

How to empty a redis database?

Hello @kartik, You have two options: FLUSHDB - clears currently ...READ MORE

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

How do I kill all the processes in Mysql “show processlist”?

Hello kartik, Mass killing operation saves time. Do it ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,840 points
2,544 views
0 votes
1 answer

Error Code: 2020. Lost connection to MySQL server during query

Hello @kartik, I got the same issue when ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,840 points
2,687 views
0 votes
1 answer

How to take MySQL database backup using MySQL Workbench?

Hii, You can export like this: Hope this is ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,840 points
1,293 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