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');

wKioL1UWvkrxuHMTAAER6D0jAF4941.jpg


舊版本,安裝後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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章