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ù)庫下的user表中已經(jīng)沒有Password字段了
而是將加密后的用戶密碼存儲于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ù)官方說明5.6以后版本,第一次啟動時(shí)會在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.
官方的方式,筆者無論是否使用--skip-grant-tables啟動mysql都測試失敗,親們可以測試:
shell>mysql -uroot -p'password' #password即.mysql_secret里的密碼 mysql>SET PASSWORD = PASSWORD('newpasswd');
舊版本,安裝后ROOT無密碼,按如下操作:
方法一:
shell>service mysqld stop #停止mysql服務(wù) shell>mysqld_safe --skip-grant-tables & #以不啟用grant-tables模式啟動mysql shell>mysql -uroot -p #輸入命令回車進(jìn)入,出現(xiàn)輸入密碼提示直接回車。 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模式啟動mysql shell>mysql -uroot -p #輸入命令回車進(jìn)入,出現(xiàn)輸入密碼提示直接回車。 mysql > set password for root@localhost = password('mysqlroot');
方法三:
shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
相關(guān)文章
解析MySQL數(shù)據(jù)庫性能優(yōu)化的六大技巧
本篇文章是對MySQL數(shù)據(jù)庫性能優(yōu)化的六大技巧進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06mysql 5.7.14 免安裝版注意事項(xiàng)(精)
這篇文章主要介紹了mysql 5.7.14 免安裝版注意事項(xiàng)的相關(guān)資料,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09MySQL數(shù)據(jù)庫優(yōu)化經(jīng)驗(yàn)詳談(服務(wù)器普通配置)
同時(shí)在線訪問量繼續(xù)增大 對于1G內(nèi)存的服務(wù)器明顯感覺到吃力嚴(yán)重時(shí)甚至每天都會死機(jī) 或者時(shí)不時(shí)的服務(wù)器卡一下 這個(gè)問題曾經(jīng)困擾了我半個(gè)多月MySQL使用是很具伸縮性的算法,因此你通常能用很少的內(nèi)存運(yùn)行或給MySQL更多的被存以得到更好的性能。2011-03-03MySQL中使用CTE獲取時(shí)間段數(shù)據(jù)的技巧分享
在數(shù)據(jù)庫操作中,獲取特定時(shí)間段的數(shù)據(jù)是一項(xiàng)常見任務(wù),MySQL自從8.0版本開始支持CTE(公共表表達(dá)式),使得我們可以更加靈活和高效地處理時(shí)間段數(shù)據(jù),本文小編介紹了MySQL中使用CTE獲取時(shí)間段數(shù)據(jù)的技巧分享,需要的朋友可以參考下2024-08-08小型Drupal數(shù)據(jù)庫備份以及大型站點(diǎn)MySQL備份策略分享
為了防止web服務(wù)器出現(xiàn)故障而引起的數(shù)據(jù)丟失,數(shù)據(jù)庫備份顯得非常重要,以免出現(xiàn)重大損失。本文分析研究一下小型的Drupal站的備份策略以及大型站點(diǎn)的mysql備份策略2014-11-11