今天我們主要是講一下關(guān)于linux忘記mysql密碼處理方法,下面提供了5種linux忘記mysql密碼找回方法哦。 方法一(先進(jìn)入root權(quán)限): # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql> update user set password=password("newpassword") where user='root'; mysql> flush privileges; mysql> quit # /etc/init.d/mysql restart # mysql -uroot -p enter password: <輸入新設(shè)的密碼newpassword> mysql> 方法二: 直接使用/etc/mysql/debian.cnf文件中[client]節(jié)提供的用戶名和密碼: # mysql -udebian-sys-maint -p enter password: <輸入[client]節(jié)的密碼> mysql> update user set password=password("newpassword") where user=root; mysql> flush privileges; mysql> quit # mysql -uroot -p enter password: <輸入新設(shè)的密碼newpassword> mysql> 方法三: 這種方法我沒有進(jìn)行過測試,因?yàn)槲业膔oot用戶默認(rèn)密碼已經(jīng)被我修改過了,那位有空測試一下,把結(jié)果告訴我,謝謝??! # mysql -uroot -p enter password: <輸入/etc/mysql/debian.cnf文件中[client]節(jié)提供的密碼> 方法四: 方法如下: 1, 關(guān)閉mysql服務(wù) /etc/init.d/mysqld stop 2,使用 –skip-grant-tables選項(xiàng)啟動mysql服務(wù),可以修 改/etc/inin.d/mysqld腳本啟動位置增加此選項(xiàng), vi /etc/init.d/mysqld 方法如下: 1, 關(guān)閉mysql服務(wù) /etc/init.d/mysqld stop 2,使用 –skip-grant-tables選項(xiàng)啟動mysql服務(wù),可以修 改/etc/inin.d/mysqld腳本啟動位置增加此選項(xiàng), vi /etc/init.d/mysqld 在下面運(yùn)行啟動的語句里增加--skip-grant-tables /usr/bin/mysqld_safe --skip-grant-tables --datadir="datadir"??socket="socketfile" --log-error="errlogfile"??pid?file="mypidfile" 加入--skip-grant-tables的意思是啟動mysql服務(wù)的時候跳 過權(quán)限表認(rèn)證。啟動后,連接到mysql的root不需要口令 3,重新啟動mysql服務(wù) /etc/init.d/mysqld start 4. 修改root用戶的密碼; mysql> update mysql.user set password=password("123456")where user=root; mysql> flush privileges; mysql> quit 5. 重新啟動mysql,就可以使用 新密碼登錄了。 mysql mysql -u root –p 輸入密碼:123456 6,關(guān)閉mysql服務(wù) /etc/init.d/mysqld stop 7, 重新修改第2步修改的/etc/init.d/mysqld,使其保持原來不變,也就是取消--skip-grant-tables語句 8,重新 啟動mysql服務(wù) /etc/init.d/mysqld start
后記:
新安裝的MySQL是有密碼的,但是其實(shí)自動存儲在了某個文件夾中,我安裝的是MySQL-server-5.6.35-1.el6.x86_64.rpm,rpm安裝方式,MySQL的root密碼;默認(rèn)的密碼存在:/root/.mysql_secret 這個文件夾中.///但是我就是打不開.SO..,就當(dāng)忘記密碼,如何找回MySQL的初始的root密碼.找到的方法都是可行的,但是唯一不好的是可能我這個版本的設(shè)置newpasswd的時候新的密碼需要用雙引號,而原博主沒有.所以轉(zhuǎn)過來備自己使用.
下附原地址:
https://www./os/201104/86881.html
|