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)'
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
2. Unload Launchctl Script
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
3. Delete Directories
sudo rm -rf /usr/local/var/mysql
4. Update Plist and Security Script
5. Install and Configure
Additional Notes:
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!