方法一:用setpassword命令
首先登陆MySQL:mysql -u root
格式:mysql> set password for 用户名@localhost = password('新密码');
例如:mysql> set password for root@localhost = password('123456');
方法二:用UPDATE直接编辑user表
切换到mysql数据库下:
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;