MySql ERROR 1045 (28000): Access denied for user &

2020-02-17 09:50发布

I've tried multiple solutions from StackOverflow but haven't had any success. I'm on Mac OSX (Sierra 10.12.3) trying to create a new database and user. From terminal I enter:

mysql -u root

which outputs this error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

To try and resolve it I stopped mysql from 'System Preferences', then from terminal typed:

sudo mysqld_safe —skip-grant-tables

I opened a second tab and entered:

mysql -u root

Then from in mysql:

update mysql.user set password_expired = 'N', authentication_string=PASSWORD('newpassword') where user = 'root';

flush privileges;

I then restart the computer (killing the process with CMD + C doesn't work). After restarting, trying mysql -u root still produces the same error.

I am able to access mysql via a MySQL client and a non-root user.

Any help is appreciated.

标签: mysql
9条回答
太酷不给撩
2楼-- · 2020-02-17 10:38

You must run your mysql by xampp-controle.exe in folder XAMPP. After that login:

mysql -u root
查看更多
仙女界的扛把子
3楼-- · 2020-02-17 10:41

Is it possible the root password is not what you think it is? Have you checked the file /root/.mysql_secret for the password? That is the default location for the automated root password that is generated from starting from version 5.7.

cat /root/.mysql_secret
查看更多
We Are One
4楼-- · 2020-02-17 10:43

just use:

$ sudo mysql

without the "-u root" parameter.

查看更多
登录 后发表回答