如果 MySQL 正在运行,首先结束mysql进程:
service mysql stop or ps aux | grep mysql killall mysqld
#启动 MySQL (非正常方式起动):
mysqld_safe --skip-grant-tables &
这样就可以不需要密码进入 MySQL :
mysql -u root -p #要求输入密码时直接回车即可
mysql> use mysql
mysql> UPDATE user SET Password=PASSWORD ('新密码') where USER='root';
mysql> flush privileges;
mysql> quit;
重新结束进程:
service mysql stop or ps aux | grep mysql killall mysqld
用正常方式启动 MySQL :
service mysql start
文章评论