一段時間沒有用mysql數據庫,今天突然需要使用,結果忘記密碼,google了下找到的解決方法,就順便記錄下,下次碰到就不需要這么麻煩了
1、輸入命令 cat /etc/mysql/debian.cnf
2、使用賬號 debian-sys-maint 賬號登錄mysql密碼為 debian.cnf 中password 值(# password 值每個人的情況不一樣,根據實際情況),在切換到mysql
3、修改root賬號密碼(自己方便修改為123456了)
update mysql.user set authentication_string=password('123456') where user='root' and Host='localhost';
update user set plugin='mysql_native_password';
flush privileges;
4、修改密碼后登錄
mysql -u root -p