MySQL如何新增用户(权限),改密码,删除用户

查看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;mysql

一、使用 root 管理员登录 mysql
mysql -uroot -p123456; 或者 mysql -h192.168.1.1 -ua1 -p123456;
二、建立新用户
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';
这个时候访问,是除了默认生成的两个数据库,看不到任何其它的数据库:
三、给某用户添加远程权限
用update命令:
mysql>use mysql;
mysql>update user set host = '%' where user = 'a1'; #给a1增长任何ip远程权限sql

用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 identified by ‘123456’ with grant option;
grant select on 想受权的数据库.
to a1@localhost identified by '123456'; #给select权限
四、删除用户
delete from mysql.user where user='a1';
4、刷新
flush privileges;
分享:数据库

相关文章
相关标签/搜索