程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> Mysql5.7忘記root密碼及mysql5.7修改root密碼的方法

Mysql5.7忘記root密碼及mysql5.7修改root密碼的方法

編輯:關於MYSQL數據庫

關閉正在運行的 MySQL :

[[email protected] ~]# service mysql stop

運行

[[email protected] ~]# mysqld_safe --skip-grant-tables &

為了安全可以這樣禁止遠程連接:

[[email protected] ~]# mysqld_safe --skip-grant-tables --skip-networking &

使用mysql連接server:

[[email protected] ~]# mysql -p

更改密碼:

mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';

*特別提醒注意的一點是,新版的mysql數據庫下的user表中已經沒有Password字段了

而是將加密後的用戶密碼存儲於authentication_string字段

mysql> flush privileges;
mysql> quit;

修改完畢。重啟

[root@localhost ~]# service mysql restart

然後mysql就可以連接了

但此時操作似乎功能不完全,還要alter user…

mysql> alter user 'root'@'localhost' identified by '123';

這樣也可以:

mysql> set password for 'root'@'localhost'=password('123');

重點給大家介紹下mysql 5.7 root密碼修改

MySQL管理者密碼設置或修改:

依據官方說明5.6以後版本,第一次啟動時會在root目錄下生產一個隨機密碼,文件名.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裡第二行內容

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服務
shell>mysqld_safe --skip-grant-tables & #以不啟用grant-tables模式啟動mysql
shell>mysql -uroot -p #輸入命令回車進入,出現輸入密碼提示直接回車。
mysql>use mysql;
mysql>update user set password=PASSWORD("123456")where user="root"; #更改密碼為 newpassord
mysql>flush privileges; #更新權限
mysql>quit #退出

方法二:

shell>service mysqld stop #停止mysql服務
shell>mysqld_safe --skip-grant-tables & #以不啟用grant-tables模式啟動mysql
shell>mysql -uroot -p #輸入命令回車進入,出現輸入密碼提示直接回車。
mysql > set password for root@localhost = password('mysqlroot');

方法三:

shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved