Home > Database > Mysql Tutorial > Why Can't I Connect to MySQL After Homebrew Installation on macOS?

Why Can't I Connect to MySQL After Homebrew Installation on macOS?

Patricia Arquette
Release: 2024-12-21 14:34:14
Original
282 people have browsed it

Why Can't I Connect to MySQL After Homebrew Installation on macOS?

Installing MySQL on macOS with Homebrew: Resolving Connection Issues

When attempting to use Homebrew to install MySQL on macOS 10.6, users may encounter difficulties connecting to the server. This article addresses the issue faced when using mysqladmin to connect with a root user.

Problem Description

Despite running mysql_install_db successfully, connecting with mysqladmin -u root password 'mypass' results in the error:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Copy after login

Potential Solution

The issue may arise due to previous installations of older MySQL versions. The following steps can resolve the problem:

1. Cleanup and Removal

brew remove mysql
brew cleanup
Copy after login

2. Unload Launchctl Script

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Copy after login

3. Delete Directories

sudo rm -rf /usr/local/var/mysql
Copy after login

4. Update Plist and Security Script

  • Modify the launchctl script string for the installed MySQL version.
  • Use the alternate security script, e.g., sudo /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation

5. Install and Configure

  • Reinstall MySQL with brew install mysql.
  • Execute mysql_install_db and start the server.
  • Run the alternate security script to set up user and password.

Additional Notes:

  • The --force option in brew cleanup removes outdated kegs.
  • The second step may not be necessary according to one commenter.
  • This solution may require starting MySQL manually with mysql.server start.

The above is the detailed content of Why Can't I Connect to MySQL After Homebrew Installation on macOS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template