1、先停止mysql服务
/etc/init.d/mysql stop
|---|------------------------| | 1 | /etc/init.d/mysql stop |
2、使用mysqld_safe启动mysql
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
|---|---------------------------------------------------------| | 1 | /usr/local/mysql/bin/mysqld_safe --skip-grant-tables & |
3、直接登录mysql
mysql -uroot
|---|--------------| | 1 | mysql -uroot |
输入
mysql> update mysql.user set authentication_string=password('新密码') where user='root'; mysql> flush privileges; mysql> quit
|-------|-------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | mysql> update mysql.user set authentication_string=password('新密码') where user='root'; mysql> flush privileges; mysql> quit |
4、最后重启mysql,就可以使用新密码登录了