11. mysql 建立使用者並授權,11mysql

來源:互聯網
上載者:User

11. mysql 建立使用者並授權,11mysql

1.建立使用者。


//登入MYSQL
@>mysql -u root -p
@>密碼
//建立使用者
mysql> insert into mysql.user(Host,User,Password) values("localhost","abc",password("1234"));
//重新整理系統許可權表
mysql>flush privileges;
這樣就建立了一個名為:abc  密碼為:1234  的使用者。

然後登入一下。

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

2.為使用者授權。

//登入MYSQL(有ROOT許可權)。我裡我以ROOT身份登入.
@>mysql -u root -p
@>密碼
//首先為使用者建立一個資料庫(test2)
mysql>create database test2;
//授權abc使用者擁有test2資料庫的所有許可權。(並且所有的ip都可以登入,注意:my.cnf中要注釋點bindress=127.0.0.1)
>grant all privileges on test2.* to 'abc'@'%' identified by '1234';
//重新整理系統許可權表
mysql>flush privileges;
mysql>其它操作

/*
如果想指定部分許可權給一使用者,可以這樣來寫:
mysql>grant select,update on test2.* to 'abc'@'%' identified by '1234';
//重新整理系統許可權表。
mysql>flush privileges;
*/

3.刪除使用者。
@>mysql -u root -p
@>密碼
mysql>DELETE FROM user WHERE User="abc" and Host="localhost";
mysql>flush privileges;
//刪除使用者的資料庫
mysql>drop database test2;

4.修改指定使用者密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="abc" and Host="localhost";

mysql>flush privileges;


薦: 歡迎交流,提出一些指導建議

相關文章

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.