mysql5.7忘记密码无法登录macos
1.mysql无法访问
$ mysql
ERROR 1045 (28000): Access denied for user 'xxx'@'localhost' (using password: NO)
2.修改配置文件跳过验证码
vim /etc/my.cnf
在最后一行加入skip-grant-tables
3.修改完重启mysql
mysql.server restart
Shutting down MySQL
.. SUCCESS!
4.再次尝试登录mysql
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37 Homebrew
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
5.切换到mysql库
mysql> show databases;
mysql> use mysql;
mysql> show tables;
6.更改root用户密码
mysql> select * from user;
mysql> update user set Password=password('123456') where User='root';
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
我安装的是mysql5.7,原来是mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
select host,user,authentication_string from user;
set authentication_string=password('123456') where User='root'; update user
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> select authentication_string from user;
7.恢复配置文件
$ vim /etc/my.cnf
最后一行删除skip-grant-tables
8.重启mysql
9.重新登录mysql
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37 Homebrew
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
10其他:
在mac 下重启mysql的命令如下:
启动MySQL服务
mysql.server start
停止MySQL服务
mysql.server stop
重启MySQL服务
mysql.server restart
GOOD NIGHT
TO
MYSELF