使用Sequel Pro连接127.0.0.1时遇MySQL连接错误(61),求解决方法
Hey there, let's figure out how to fix that MySQL connection error you're seeing! The Can't connect to MySQL server on '127.0.0.1' (61) error typically means your local MySQL server isn't accessible, so here are the step-by-step fixes you can try:
First things first—if the server isn't up, you can't connect to it. Depending on how you installed MySQL on your Mac:
- If you used Homebrew, run this command to check status:
If MySQL shows as "stopped", start it with:brew services listbrew services start mysql - If you installed it via the official DMG, check with launchctl:
Start it with:sudo launchctl list | grep mysqlsudo launchctl start com.mysql.mysqld
By default, MySQL uses port 3306. If it's using a different port or not listening at all, you'll get this error. Run this command to check:
lsof -i :3306
If you don't see any MySQL-related entries here, either:
- Update your Sequel Pro connection settings to use the correct port (if you changed it manually), or
- Edit your MySQL config file (
my.cnformy.ini, usually found in/usr/local/mysql/etc/or/etc/) to setport = 3306and restart the server.
Sometimes macOS's built-in firewall can block local MySQL connections. To test this temporarily:
- Open System Preferences > Security & Privacy > Firewall
- Click the lock to make changes, then turn off the firewall
- Try connecting with Sequel Pro again. If it works, add MySQL to the firewall's allowed apps list before turning the firewall back on.
Open your MySQL config file and check these two key settings:
bind-address: This should be set to127.0.0.1(allow only local connections) or0.0.0.0(allow all connections). If it's set to a different IP, local connections will fail.skip-networking: If this line exists and isn't commented out, it disables TCP/IP connections entirely. Comment it out with a#at the start of the line.
After making changes, restart MySQL to apply them.
Sometimes users are set up only to connect via localhost (which uses a Unix socket, not TCP/IP), but 127.0.0.1 uses TCP/IP. To fix this:
- First, connect to MySQL using the socket (run
mysql -u rootin Terminal if you don't have a password, ormysql -u root -pto enter your password) - Run these commands to grant access for your user to connect via 127.0.0.1:
ReplaceGRANT ALL PRIVILEGES ON *.* TO 'your_username'@'127.0.0.1' IDENTIFIED BY 'your_password' WITH GRANT OPTION; FLUSH PRIVILEGES;your_usernameandyour_passwordwith your actual MySQL credentials.
If none of the above fixes work, there might be a corruption in your MySQL installation. Make sure to back up any databases you need first, then uninstall MySQL completely and reinstall it using your preferred method (Homebrew, official DMG, etc.).
内容的提问来源于stack exchange,提问作者user9289573

