1、Mysql库外修改
mysql -uroot -p'old-passowrd' password 'new-password';
2、MySQL库内修改
更改密码:
update mysql.user set authentication_string=password('new_password') where user='root' and host='localhost';
刷新权限:
flush privileges;
修改自己(此时登录的账号)
set password=password('new_password');
3、忘记root密码怎么修改
# 1、编辑 /etc/my.cnf 配置文件;vim /etc/my.cnf
在 [mysqld] 下添加 skip-grant-tables
# 2、重启 mysql 服务:systemctl restart mysqld
# 3、mysql -uroot 进入数据库
修改 root 用户密码,例如:update mysql.user set authentication_string=password('new_passwo rd') where user='root'
flush privileges;。
# 4、把 /etc/my.cnf 中的 skip-grant-tables 注释掉,然后重启 mysql。