mysql忘記密碼怎么辦
發(fā)布日期:2022-04-12 09:01 | 文章來源:源碼中國(guó)
MySQL忘記密碼的解決辦法:
[root@localhost ~]# mysql -uroot -p ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
如果說出現(xiàn)這個(gè)一般就是因?yàn)镸ySQL沒有起來
[root@localhost ~]# mysql -uroot -p ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
當(dāng)出現(xiàn)這個(gè)的一般就是因?yàn)槊艽a輸入錯(cuò)誤
解決辦法:
1.停掉MySQL
[root@localhost ~]# service mysqld stop Stopping mysqld: [ OK ]
2.修改配置文件,在最后一行加入以下內(nèi)容
skip-grant-tables //跳過授權(quán)直接進(jìn)入數(shù)據(jù)庫(kù)
3.重啟MySQL
[root@localhost ~]# service mysqld start [root@localhost ~]# mysql -uroot -p mysql>
4.重新給MySQL設(shè)置密碼
mysql> use mysql //密碼存放在MySQL中,需要進(jìn)入
mysql> desc user; //查看user表中的字段
密碼一般存在password表中
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
mysql> update user set password=password('passw0rd') where user="root"; //設(shè)置密碼為passw0rd
mysql> flush privileges; //刷新
5.然后退出重新登陸
[root@localhost ~]# mysql -uroot -ppassw0rd mysql>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信