将MySQL连接到Apache Superset时遇1045权限错误求助
Let's break down why you're hitting this 1045 error even after running the GRANT statement, and walk through actionable fixes tailored to your MAMP setup:
Verify the Host Mapping for Your User
MAMP's MySQL sometimes treatslocalhostdifferently than expected. Local connections might use a socket instead of TCP/IP, which can map to127.0.0.1rather thanlocalhostin MySQL's user table.
First, run this query in MAMP's MySQL shell (usually located at/Applications/MAMP/Library/bin/mysql):SELECT user, host FROM mysql.user WHERE user = 'supersetuser';If you don't see an entry for
supersetuser@127.0.0.1, add it with:GRANT ALL PRIVILEGES ON `apache_superset`.* TO 'supersetuser'@'127.0.0.1' WITH GRANT OPTION; FLUSH PRIVILEGES;Then update your SQLAlchemy URI to use
127.0.0.1instead oflocalhost:mysql://supersetuser:superset@127.0.0.1:8889/apache_supersetTry Connecting via MAMP's MySQL Socket
MAMP uses a dedicated socket file for local connections, which can bypass TCP/IP port issues. First, find the socket path (typically/Applications/MAMP/tmp/mysql/mysql.sock), then modify your URI to use it:mysql://supersetuser:superset@localhost/apache_superset?unix_socket=/Applications/MAMP/tmp/mysql/mysql.sockNote: You don't need to specify port 8889 when using a socket connection.
Double-Check MAMP's Port Configuration
Open MAMP's preferences, navigate to the Ports tab, and confirm MySQL is actually running on port 8889. If you've changed the port recently, restart MAMP to apply the setting fully.Confirm the
apache_supersetDatabase Exists
Permissions won't matter if the target database doesn't exist. Run this query to verify:SHOW DATABASES LIKE 'apache_superset';If it's missing, create it with:
CREATE DATABASE apache_superset;Then re-run your original GRANT statement to ensure permissions are applied to the existing database.
Rule Out Password Escaping Issues
If your password ever includes special characters (like@,:, or/), you'll need to URL-encode them in the URI. For example,sup@rsetbecomessup%40rset. While your current passwordsupersetdoesn't have this issue, it's a good thing to keep in mind for future changes.
内容的提问来源于stack exchange,提问作者Giorgos Myrianthous

