停止Mysql服務
/etc/init.d/mysqld stop
使用mysql_safe 附帶的 “--skip-grant-tables”(忽略授權登錄驗證)
mysql_safe --skip-grant-tables --user=mysql >/dev/null 2>&1 &
查看數(shù)據(jù)庫服務是否開啟
ss -lnt | grep 3306
OK,現(xiàn)在可以不用密碼登錄啦
修改root密碼為新密碼
set password=password('新密碼')
重啟服務
/etc/init.d/mysqld stop
/etc/init.d/mysqld start