1. 檢查mysql服務(wù)是否啟動(dòng),如果啟動(dòng),關(guān)閉mysql服務(wù)
運(yùn)行命令:ps -ef | grep -i mysql

如果開著就運(yùn)行關(guān)閉的命令:service mysqld stop

2.修改mysql的配置文件my.conf
一般在/etc目錄下,運(yùn)行命令:vi /etc/my.cnf,編輯文件

在文件的[mysqld]標(biāo)簽下添加一句:skip-grant-tables

然后wq!保存退出。
3.重啟數(shù)據(jù)庫(kù)
運(yùn)行命令:service mysqld start
4.重啟數(shù)據(jù)庫(kù)
運(yùn)行命令:service mysqld start
5.進(jìn)入到mysql數(shù)據(jù)庫(kù)
運(yùn)行命令:mysql -u root

6.進(jìn)入到mysql數(shù)據(jù)庫(kù)
運(yùn)行命令:mysql -u root
7.修改密碼
以下是5.6的方式
運(yùn)行語(yǔ)句:use mysql;
繼續(xù)運(yùn)行語(yǔ)句:update mysql.user set password=password('root_password') where user='root';
root_password替換成你想要的密碼
以下是5.7的方式
運(yùn)行語(yǔ)句:use mysql;
繼續(xù)運(yùn)行語(yǔ)句:update mysql.user set authentication_string=password('root_password') where user='root';
root_password替換成你想要的密碼

8.把步驟2加的東西刪除掉,在重啟服務(wù)器,就可以使用剛才修改的密碼登錄進(jìn)服務(wù)器了。
mysql -u root -p
到這一步已經(jīng)全部結(jié)束。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。