MySQL資料庫下如何為使用者佈建密碼

來源:互聯網
上載者:User

當初次在機器上安裝完Mysql時,你可以匿名進行訪問資料庫或者以不帶口令的root身份進入資料庫.另外如果你是一個管理員,你還要進行一些使用者的建立及授權,這又涉及到設定密碼的問題.下面我們就討論一下如何設定密碼:

首先我們應該知道Mysql資料庫中的口令儲存必須用password()函數加密它.因為在user表中是以加密形式儲存口令,而不是作為純文字.如果你沒有加密,直接在資料庫中執行以下語句:

use mysql

insert into user (host,user,password) values('%','user_name','your password');

flush privileges;

相信結果不會讓你滿意.因為伺服器比較的是加密的值,所以伺服器串連一定失敗.這裡需要說明的是flush privileges;這條命令起到了重新載入授權表.你也可以在shell下直接用mysqladmin -u root reload或者mysqladmin -u root flush-privileges來實現重載授權表.

在Mysql環境下,你可以使用以下語句進行設定密碼:

1.insert into user(host,user,password) values('%','user_name',password("your password");

2.set password for user_name = password("your password")

以上兩種方法都必須進行重載授權表.

3.當然你也可以在建立一個使用者時直接設定密碼,grant語句將為你自動加密口令.

如 :grant all on *.* to user_name@% identified by "your password";

另外你也可以在shell環境下用mysqladmin程式來設定密碼

如: mysqladmin -u root password "your password"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.