修改mysql的root用户密码

先停止mysql服务

macos 可以用

brew services stop mysql

mysql.server stop
用mysqld_safe启动mysql
mysqld_safe --skip-grant-tables
mysql 5.7或以上可以在 my.cnf配置文件 [mysqld] 添加
[mysqld]
skip-grant-tables
进入mysql命令行
设置root密码
set password for 'root'@'localhost' = password('你的密码');

报错

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

解决:命令行先输入,再输更新密码命令

FLUSH PRIVILEGES;
用update user表方式更改:
use mysql;
update user set password=password('your_password') where user='root' and host='localhost';
flush privileges;

如果报错,可以试试

update user set authentication_string=password('你的密码') where user='root';
update user set plugin="mysql_native_password" where user='root';
刷新
flush privileges;
退出
quit;
启动mysql
brew services start mysql

mysql.server start
完成!