MYSQL添加新使用者 MYSQL為使用者建立資料庫 MYSQL為新使用者指派許可權

來源:互聯網
上載者:User

標籤:blog   ar   os   sp   strong   資料   div   on   log   

1.建立使用者

//登入MYSQL

@>mysql -u root -p@>密碼//建立使用者mysql> insert into mysql.user(Host,User,Password) values(‘localhost’,‘jeecn’,password(‘jeecn’));

//重新整理系統許可權表

mysql>flush privileges;

 這樣就建立了一個名為:jeecn  密碼為:jeecn  的使用者。

//退出後登入一下

mysql>exit;@>mysql -u jeecn -p@>輸入密碼mysql>登入成功

 2.為使用者授權

//登入MYSQL(有ROOT許可權)。我裡我以ROOT身份登入.
@>mysql -u root -p
@>密碼
//首先為使用者建立一個資料庫(jeecnDB)
mysql>create database jeecnDB;
//授權jeecn使用者擁有jeecn資料庫的所有許可權
@>grant all  on jeecnDB.* to [email protected] identified by ‘jeecn’;
//重新整理系統許可權表
mysql>flush privileges;
mysql>其它操作

//如果想指定部分許可權給一使用者,可以這樣來寫:
mysql>grant select,update on jeecnDB.* to [email protected] identified by ‘jeecn’;
//重新整理系統許可權表。
mysql>flush privileges;

mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘串連口令’;

許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。
當許可權1,許可權2,…許可權n被all privileges或者all代替,表示賦予使用者全部許可權。
當資料庫名稱.表名稱被*.*代替,表示賦予使用者動作伺服器上所有資料庫所有表的許可權。
使用者地址可以是localhost,也可以是ip地址、機器名字、網域名稱。也可以用’%’表示從任何地址串連。
‘串連口令’不可為空,否則建立失敗。

例如:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者jee分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。

mysql>grant all  on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者jee分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all  on *.* to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者jee分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to [email protected] identified by ‘123′;
給本機使用者jee分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

3.刪除使用者

@>mysql -u root -p
@>密碼
mysql>DELETE FROM user WHERE User=”jeecn” and Host=”localhost”;
mysql>flush privileges;
//刪除使用者的資料庫
mysql>drop database jeecnDB;

4.修改指定使用者密碼

@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password(‘新密碼’) where User=”jeecn” and Host=”localhost”;
mysql>flush privileges;
mysql>quit;

MYSQL添加新使用者 MYSQL為使用者建立資料庫 MYSQL為新使用者指派許可權

聯繫我們

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