關閉正在運行的 MySQL :mysql
1sql |
[root@www.woai.it ~]# service mysql stop shell |
運行數據庫
1安全 |
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables & ide |
爲了安全能夠這樣禁止遠程鏈接:測試
1ui |
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables --skip-networking & 加密 |
使用mysql鏈接server:spa
1 |
[root@www.woai.it ~]# mysql -p |
更改密碼:
1 |
mysql> update mysql. user set authentication_string= password ( '123qwe' ) where user = 'root' and Host = 'localhost' ; |
*特別提醒注意的一點是,新版的mysql數據庫下的user表中已經沒有Password字段了
而是將加密後的用戶密碼存儲於authentication_string字段
1 2 |
mysql> flush privileges ; mysql> quit; |
修改完畢。重啓
而後mysql就能夠鏈接了
但此時操做彷佛功能不徹底,還要alter user…
1 |
mysql> alter user 'root' @ 'localhost' identified by '123' ; |
這樣也能夠:
1 |
mysql> set password for 'root' @ 'localhost' = password ( '123' ); |
重點給你們介紹下mysql 5.7 root密碼修改
MySQL管理者密碼設置或修改:
依據官方說明5.6之後版本,第一次啓動時會在root目錄下生產一個隨機密碼,文件名.mysql_secret。
1 2 3 4 5 |
[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裏第二行內容
1 2 |
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都測試失敗,親們能夠測試:
1 2 |
shell>mysql -uroot -p 'password' # password 即.mysql_secret裏的密碼 mysql> SET PASSWORD = PASSWORD ( 'newpasswd' ); |

舊版本,安裝後ROOT無密碼,按以下操做:
方法一:
1 2 3 4 5 6 7 |
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 #退出 |
方法二:
1 2 3 4 |
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' ); |
方法三:
1 |
shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p |
參考:http://www.jb51.net/article/77858.htm
忘記mysql root用戶密碼的解決辦法(skip-grant-tables)
skip-grant-tables
顧名思義,數據庫啓動的時候 跳躍權限表的限制,不用驗證密碼,直接登陸。
注意:
這種狀況只有在忘記root密碼 不得已重啓數據庫的狀況下使用的。現網環境慎用,須要重啓數據庫,而且安全性也比較難以保證。
1.修改配置參數
/etc/my.cnf
在
[mysqld] 下面加上:
skip-grant-tables
配置項。
2.重啓MySQL
使得參數生效:
service mysqld restart
3.注意事項
此時全部用戶登陸當前數據庫都是免密碼的,因此此時數據庫的安全性是很是低的。
4.修改密碼
具體的辦法:
參考以上介紹
5.去掉參數
a.密碼修改好了以後再將配置文件中 skip-grant-tables去掉
b.再次重啓數據庫。