So in my terminal, I can login to mySQL with mysql -u root -p in one tab, but not in…
- User
So in my terminal, I can login to mySQL with mysql -u root -p in one tab, but not in another tab. Why?
The error message:
mysql -u -root -p Enter password: ERROR 1045 (28000): Access denied for user '-root'@'localhost' (using password: YES)
- Assistant
The issue arises due to a small typo in the command you're using in the failing terminal tab. In the working tab, you correctly use:
shellmysql -u root -pHowever, in the tab where it fails, you use:
shellmysql -u -root -pNotice the extra dash before
rootin the failing command (-rootinstead ofroot). When you include the extra dash, the MySQL client interprets-rootas the username, including the dash. Therefore, it tries to authenticate the user-root, which doesn't exist, leading to the "Access denied" error.To fix the issue, remove the extra dash:
shellmysql -u root -pExplanation:
-uis a command-line option that specifies the MySQL username.