Home  >  Article  >  Database  >  How to Resolve MySQL Connection Error: Socket Not Found or Accessible?

How to Resolve MySQL Connection Error: Socket Not Found or Accessible?

Linda Hamilton
Linda HamiltonOriginal
2024-10-24 04:09:31458browse

How to Resolve MySQL Connection Error: Socket Not Found or Accessible?

MySQL Connection Error: Socket Not Found or Accessible

When attempting to connect to MySQL using MAMP, you may encounter error #2002: "Can't connect to local MySQL server through socket." This error typically indicates that the MySQL socket file, typically located at "/Applications/MAMP/tmp/mysql/mysql.sock," cannot be found or is inaccessible.

Diagnosis

To diagnose the issue, navigate to the tmp/mysql directory and inspect its contents. If the mysql.sock file is not present, or if it is present but you receive a permission denied error, proceed with the following troubleshooting steps.

Troubleshooting

Test

Try starting MySQL using the full path to the executable:

/Applications/MAMP/Library/bin/mysql -u root -p

Fix

If the above step succeeds, create a symbolic link to the mysql.sock file using the following command:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Resolution

Restart MySQL and connect using the following command:

mysql -u root -p

Alternate Fix

If the above steps fail, you can dynamically search for the MySQL executable path:

$($(for dir in /usr/local/mysql/bin /usr/bin /usr/local/bin /Applications/MAMP/Library/bin /Applications/XAMPP/xamppfiles/bin; do [ -x "$dir/mysql" ] && echo "$dir/mysql" && break; done) -u root -p)

The above is the detailed content of How to Resolve MySQL Connection Error: Socket Not Found or Accessible?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn