Mysql5.7忘記root密碼及mysql5.7修改root密碼的方法
關(guān)閉正在運(yùn)行的 MySQL :
[root@www.woai.it ~]# service mysql stop
運(yùn)行
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables &
為了安全可以這樣禁止遠(yuǎn)程連接:
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables --skip-networking &
使用mysql連接server:
[root@www.woai.it ~]# mysql -p
更改密碼:
mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
*特別提醒注意的一點(diǎn)是,新版的mysql數(shù)據(jù)庫(kù)下的user表中已經(jīng)沒(méi)有Password字段了
而是將加密后的用戶密碼存儲(chǔ)于authentication_string字段
mysql> flush privileges; mysql> quit;
修改完畢。重啟
[root@localhost ~]# service mysql restart
然后mysql就可以連接了
但此時(shí)操作似乎功能不完全,還要alter user…
mysql> alter user 'root'@'localhost' identified by '123';
這樣也可以:
mysql> set password for 'root'@'localhost'=password('123');
重點(diǎn)給大家介紹下mysql 5.7 root密碼修改
MySQL管理者密碼設(shè)置或修改:
依據(jù)官方說(shuō)明5.6以后版本,第一次啟動(dòng)時(shí)會(huì)在root目錄下生產(chǎn)一個(gè)隨機(jī)密碼,文件名.mysql_secret。
[root@bright ~]# cat /root/.mysql_secret # Password set for user 'root@localhost' at 2015-03-27 23:12:10 :Jj+FTiqvyrF [root@bright ~]# cd /usr/local/mysql/bin/ [root@bright bin]# ./mysqladmin -u root -h localhost password '123456' -p
Enter password: #此行輸入.mysql_secret里第二行內(nèi)容
mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
官方的方式,筆者無(wú)論是否使用--skip-grant-tables啟動(dòng)mysql都測(cè)試失敗,親們可以測(cè)試:
shell>mysql -uroot -p'password' #password即.mysql_secret里的密碼
mysql>SET PASSWORD = PASSWORD('newpasswd');

舊版本,安裝后ROOT無(wú)密碼,按如下操作:
方法一:
shell>service mysqld stop #停止mysql服務(wù)
shell>mysqld_safe --skip-grant-tables & #以不啟用grant-tables模式啟動(dòng)mysql
shell>mysql -uroot -p #輸入命令回車(chē)進(jìn)入,出現(xiàn)輸入密碼提示直接回車(chē)。
mysql>use mysql;
mysql>update user set password=PASSWORD("123456")where user="root"; #更改密碼為 newpassord
mysql>flush privileges; #更新權(quán)限
mysql>quit #退出
方法二:
shell>service mysqld stop #停止mysql服務(wù)
shell>mysqld_safe --skip-grant-tables & #以不啟用grant-tables模式啟動(dòng)mysql
shell>mysql -uroot -p #輸入命令回車(chē)進(jìn)入,出現(xiàn)輸入密碼提示直接回車(chē)。
mysql > set password for root@localhost = password('mysqlroot');
方法三:
shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
相關(guān)文章
MySQL數(shù)據(jù)庫(kù)優(yōu)化的六種方式總結(jié)
關(guān)于數(shù)據(jù)庫(kù)優(yōu)化,網(wǎng)上有不少資料和方法,但是不少質(zhì)量參差不齊,所以下面這篇文章主要給大家介紹了關(guān)于MySQL數(shù)據(jù)庫(kù)優(yōu)化的六種方式,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01
MySql帶OR關(guān)鍵字的多條件查詢(xún)語(yǔ)句
MySQL帶OR關(guān)鍵字的多條件查詢(xún),與AND關(guān)鍵字不同,OR關(guān)鍵字,只要記錄滿足任意一個(gè)條件,就會(huì)被查詢(xún)出來(lái)。即AND的優(yōu)先級(jí)高于OR2017-07-07
MySql服務(wù)器系統(tǒng)變量和狀態(tài)變量介紹
這篇文章主要介紹了MySql服務(wù)器系統(tǒng)變量和狀態(tài)變量介紹,本文分別講解了它們的作用、設(shè)置方法和獲取方法,需要的朋友可以參考下2014-12-12
mysql 鎖表鎖行語(yǔ)句分享(MySQL事務(wù)處理)
下面這個(gè)語(yǔ)句是鎖定一行數(shù)據(jù),開(kāi)始讀取,一直到刪除后都不會(huì)有第二個(gè)人也讀到這條數(shù)據(jù)2011-09-09
MySQL 基于時(shí)間點(diǎn)的快速恢復(fù)方案
這篇文章主要介紹了MySQL 基于時(shí)間點(diǎn)的快速恢復(fù)方案,幫助大家更好的理解和使用MySQL,感興趣的朋友可以了解下2020-11-11
解決mysql使用not in 包含null值的問(wèn)題
這篇文章主要介紹了解決mysql使用not in 包含null值的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01

