忘记mysql密码后重新设置mysql密码的方法
mysqld_safe --user=mysql --skip-grant-tables &
update mysql.user set password=password('root') where user='root' and host='localhost';
退出后重新启动mysql
mysqld_safe --user=mysql &
然后就可以使用重新设置好的用户名密码登陆了
正常登陆mysql后可以使用三种方式设置mysql的密码
在mysql里面设置
set password for 'root'@'localhost'=password('root')
grant 语句
grant all on *.* to 'root'@'localhost' identified by 'root' with grant option;
update语句
update mysql.user set password=password('root') where user='root' and host='localhost';
在mysqladmin中设置,在没有登陆mysql之前设置
mysqladmin -uroot -proot password 'myroot' 回车后输入旧密码
总结:如果启动mysql的时候(使用mysqld_safe启动)使用了 --skip-grant-tables 参数,则只有登陆到mysql中使用update语句直接修改mysql.user表中的user='root' and host='localhost'的记录可以生效,其他几种方法在使用了 --skip-grant-tables参数后无效。
mysqld_safe --user=mysql --skip-grant-tables &
update mysql.user set password=password('root') where user='root' and host='localhost';
退出后重新启动mysql
mysqld_safe --user=mysql &
然后就可以使用重新设置好的用户名密码登陆了
正常登陆mysql后可以使用三种方式设置mysql的密码
在mysql里面设置
set password for 'root'@'localhost'=password('root')
grant 语句
grant all on *.* to 'root'@'localhost' identified by 'root' with grant option;
update语句
update mysql.user set password=password('root') where user='root' and host='localhost';
在mysqladmin中设置,在没有登陆mysql之前设置
mysqladmin -uroot -proot password 'myroot' 回车后输入旧密码
总结:如果启动mysql的时候(使用mysqld_safe启动)使用了 --skip-grant-tables 参数,则只有登陆到mysql中使用update语句直接修改mysql.user表中的user='root' and host='localhost'的记录可以生效,其他几种方法在使用了 --skip-grant-tables参数后无效。