情況一:
在已知密碼的情況下修改mysql管理密碼:
mysqladmin -uroot -p123 password 123456
情況二:
在忘記mysql登入密碼的情況下,清空或登入mysql管理密碼:
1.#停止mysqld服務
/etc/init.d/mysqld stop
2.#使用mysqld_safe啟動伺服器。這樣啟動mysql将允許任何人以root使用者和空密碼通路mysql伺服器
#允許本和網絡遠端登入
/application/mysql/bin/mysqld_safe --skip-grant-tables&
#不允許網絡遠端登入(建議)
/application/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking &
3.#使用mysql語句直接登入,這裡不需要密碼
mysql
4#.使用MySQL語句修改密碼,修改授權表
5.6版本:
mysql>use mysql;update mysql.user set password=PASSWORD('123') where user='root' and host='localhost'; #把root使用者更新密碼為 123456
exit #退出
5.7版本中的:password字段改成authentication_strings
update mysql.user set authentication_string=PASSWORD('123') where user='root' and host='localhost';
5.#然後重新開機mysql,這樣mysql的root密碼就修改了
/etc/init.d/mysqld restart