MySQL如何新增使用者(許可權),改密碼,刪除使用者

2021-09-27 04:57:38 字數 1368 閱讀 7126

檢視mysql資料庫中所有使用者

mysql>use mysql;

mysql>select host, user from user;

或者mysql> select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;

檢視資料庫中具體某個使用者的許可權

mysql>show grants for root@localhost;

1、使用 root 管理員登陸 mysql

mysql -uroot -p123456; 或者 mysql -h192.168.1.1 -ua1 -p123456;

2、建立新使用者

create user a1@localhost identified by '123456'; #建立只能本地登陸的使用者

create user a1@% identified by '123456'; #建立可以外網登陸的使用者

'%' - 所有情況都能訪問

『localhost』 - 本機才能訪問

111.222.33.44 - 指定 ip 才能訪問

注:修改密碼

update mysql.user set password=password('新密碼') where user='user1';

這個時候訪問,是除了預設生成的兩個資料庫,看不到任何其它的資料庫:

3、給某使用者新增許可權

用update命令:

mysql>use mysql;

mysql>update user set host = '%' where user = 'a1'; #給a1增加任何ip所有許可權

或者用grant 命令:

grant all on 想授權的資料庫.to a1@'%'; #給任何ip所有許可權

grant all on 想授權的資料庫. to a1@localhost; #給localhost所有許可權

grant all on 想授權的資料庫.to a1@localhost identified by '123456'; #同時建立使用者並授權 注意:用以上命令授權的使用者不能給其它使用者授權,如果想讓該使用者可以授權,用以下命令:

grant on 想授權的資料庫. to a1@localhost with grant option;

grant select on 想授權的資料庫.* to a1@localhost identified by '123456'; #給select許可權

4、刪除使用者

delete from mysql.user where user='a1';

四、重新整理

flush privileges;

分享:

mysql新增使用者和使用者許可權

mysql新增使用者 使用可以對mysql資料庫使用者表有操作許可權的使用者名稱登陸mysql insert into user host,user,password values name password 如果work使用者沒有登陸許可權,則 killall mysqld share mysql...

mysql新增使用者和使用者許可權

mysql新增使用者 使用可以對mysql資料庫使用者表有操作許可權的使用者名稱登陸mysql insert into user host,user,password values name password 如果work使用者沒有登陸許可權,則 killall mysqld share mysql...

使用者許可權 mysql新增使用者及賦予許可權

建立使用者 use mysql 建立使用者需要操作 mysql 表 語法格式為 host host 為 localhost 表示本地登入使用者,host 為 ip位址或 ip 位址區間,表示指定ip位址的主機可登入,host 為 表示所有主機都可登入,省略代表所有主機create user user...