設定及修改mysql root 使用者密碼

來源:互聯網
上載者:User

標籤:mysql 5.5 密碼

mysql的安全

首先進入後

1.先給mysql 設定一個密碼

2.刪除無用的mysql庫內的使用者帳號

3.刪除預設存在的test資料庫



還可以做到更安全的

1.刪除所有mysql中的使用者,包括root超級使用者。

mysql>delete from mysql.user;

Query OK,2 rows affected(0.00 sec)

提示:root可以保留,然後修改為其它使用者也可以

2.增加system 並提升為超級管理員,即和root等價的使用者,只是名字不同。

mysql>grant all privileges on *.* [email protected]‘localhost‘ identified by ‘密碼‘  with grant option; 

Query OK,0 rows affected (0.00 sec)


強烈建議先建立使用者再刪除 root


設定密碼


mysqladmin -u root password ‘密碼‘

(這是在沒有初始密碼的前提下設定)

mysqladmin -u root -p‘密碼‘ password‘oldboy‘ -S /data/3306/mysql.sock     (多執行個體方式)


修改密碼

1.命令列修改

mysqladmin -u root -p‘456‘ password ‘123‘   (密碼由456改成123)(最常用的方法)

2.sql語句修改法



desc mysql.user;   (查看使用者表表結構)


select user,host,password from mysql.user;

update mysql.user set password=‘456‘  where user=‘root‘ and host =‘localhost‘  (此方法不可行,因為是明文,也不會成功)


正確的應該是

update mysql.user set password=password(456) where user = ‘root‘ host = ‘localhost‘;


flush privileges;


在sql語句中更改目前使用者密碼也可以用

set password=password(‘123456‘)


建議:修改密碼後重新整理一下

flush privileges;



設定及修改mysql root 使用者密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.