Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/The complete guide to the mysqli_real_connect(): (hy000/2002): no such file or directory issue
Next
In Process
Zoé Hamel
  • 28
Zoé Hamel
Asked: May 18, 20222022-05-18T14:50:45+00:00 2022-05-18T14:50:45+00:00In: php

The complete guide to the mysqli_real_connect(): (hy000/2002): no such file or directory issue

  • 28

. Advertisement .

..3..

. Advertisement .

..4..

Hi everyone, I’m learning about php. While working, I try run PhpMyAdmin on MacOS. As a result, I get the message:

mysqli_real_connect(): (HY000/2002): No such file or directory

What can I do about the “mysqli_real_connect(): (hy000/2002): no such file or directory” issue? Is there a better approach?

no such file or directory
  • 5 5 Answers
  • 139 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

5 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Mohamed Voisin
    2022-05-18T14:50:59+00:00Added an answer on May 18, 2022 at 2:50 pm

    change localhost to 127.0.0.1 in /etc/phpmyadmin/config.inc.php

    $cfg['Servers'][$i]['host'] = '127.0.0.1';

    This is because pma attempts to connect to mysql.socket when you use localhost. PMA will establish a TCP connection if you use 127.0.0.1.

    • 23
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Noah Millet
    2022-05-18T14:50:52+00:00Added an answer on May 18, 2022 at 2:50 pm

    Perhaps your SQL server was stopped

    sudo /etc/init.d/mysql start

    Or

    sudo service mysqld start

    Useservice mysql status to verify your status


    EDIT Adding from Comments:

    Use:

    sudo systemctl enable mysql 

    To continue running MySQL.

    • 18
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Jade Marie
    2022-05-18T14:50:56+00:00Added an answer on May 18, 2022 at 2:50 pm

    This is what I tried before

    cd /opt/lampp/phpmyadmin

    Next

    gedit config.inc.php

    This is what you need

    $cfg['Servers'][$i]['host'] = 

    localhost should be changed to 127.0.0.1

    Notice: ‘//’ Remove // before $cfg['Servers'][$i]['host']

    I have checked http://localhost/phpmyadmin/ again

    Mysqli stated:

    “phpMyAdmin tried to connect to the MySQL server, and the server
    rejected the connection. You should check the host, username and
    password in your configuration and make sure that they correspond to
    the information given by the administrator of the MySQL server.”

    I opened config.inc.php again and found it.

    $cfg['Servers'][$i]['password'] =

    Enter your password to create the password

    It worked for me. It might work for you.

    • 8
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Lucas Arnaud
    2022-05-18T14:51:02+00:00Added an answer on May 18, 2022 at 2:51 pm

    mysqli_connect() (HY000/2002: No such file/directory

    Background:

    I just wanted to run some PHPUnit testing on my Mac using Terminal. One of the classes that I wanted to test was the ability to connect MySQL DB. This was created and managed PHPMyAdmin. The web app that I was using was fine in localhost. When I tried to run the testcases, I received the following error:

    mysqli_connect(): (HY000/2002): No such file or directory

    Solution:

    With the itchiness, I needed to find a solution. I also searched in a few SOQ&A threads for help and tried it out. I found that a combination of these changes worked well for me.

    1. Find your PHPMyAdmin config.inc.php file.
    2. Find the $cfg['Servers'][$i]['host'] line. This line may have been commented out by default. Please uncomment it.
    3. Replace that line with the following:

    $cfg['Servers'][$i]['host'] = '127.0.0.1';

    1. It can be saved and restarted from the XAMPP control panel (manager -osx).
    2. To change your $host parameter value, use the mysqli_connect() method.

    $_connection = mysqli_connect(**"localhost: 3306"**, $_mysql_username, $_mysql_password, $_database);

    Note : This is my default MySQL port number, 3306. Before you follow these steps, make sure to verify your MySQL Port number.

    That’s it. These steps were the only ones that worked for me. It worked fine after I ran the Unit Tests. The DB data was also properly updated according to the tests.

    This is how it works

    It works because sometimes, the mysqli_connect method (IP Address of the DB Host and Port number) requires a working socket. If you’ve commented out $cfg['Servers'][$i]['host'] = '127.0.0.1'; or set ‘localhost” as the value, the port number is ignored. If you want to use a socket, you will need to use ‘127.0.0.1 or the actual hostname. The above steps must be followed regardless of what default port number you have. For more information, please refer to the link in PHPMyAdmin.

    We hope this helps someone else.

    Cheers!

    • 6
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. Anna Tanguy
    2022-05-18T14:50:49+00:00Added an answer on May 18, 2022 at 2:50 pm

    This worked well for me.

    Find config.sample.inc.php

    Change

    $cfg['Servers'][$i]['host'] = 'localhost';

    In

    $cfg['Servers'][$i]['host'] = '127.0.0.1';

    Save.

    Next, rename the file.

    • 5
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.