11 mysql 建立使用者並授權

2021-06-28 04:54:13 字數 1435 閱讀 3740

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;

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

MySql建立使用者並授權

本文簡單描述如何在mysql下完成使用者的建立授權等操作 登陸mysql 使用root使用者登陸mysql jacky gentoo mysql uroot p xx xx代表各自的密碼 mysql create user pysite localhost identified by xx 自此完成...

MySQL 建立使用者並授權

create user username host identified by password 說明 示例 create user jack localhost identified by 123456 create user rose 192.168.38.110 idendified by 1...

mysql建立使用者並授權

create database db create user user identified by pwd grant all privileges on db to user create user user admin identified by pwd grant select,insert,...