文章目录
一、创建账户并授予数据库权限
1、通用语法:
create user ‘username’@‘host’ identified by ‘password’;
grant privileges on database.table to ‘username’@‘host’;
1.1 普通用户举例
创建本地用户 tom,并授予tomdb数据库的增删查改权限
create user ‘tom’@‘localhost’ identified by ‘tomtom’;
grant all on tomdb.* to ‘tom’@‘localhost’;
1.2 管理员用户举例
使普通用户拥有给其他用户授权的权限,类似管理员
创建本地用户 tim,并授予timdb数据库的增删查改权限
create user ‘tim’@‘localhost’ identified by ‘timtim’ with grant option;
grant all on timdb.* to ‘tim’@‘localhost’;
二、查询用户名及主机
use mysql
select user,host from user;
三、删除用户
1、默认情况下删除’username’@’%’
drop user username;
2、删除指定host的用户
drop user ‘username’@‘host’;
四、修改用户密码
grant all on database.table to ‘username’@‘host’ identified by ‘password’;
五、附录
1、权限说明:
all:所有权限。
select:读取权限。
delete:删除权限。
update:更新权限。
create:创建权限。
drop:删除数据库、数据表权限。
2、host说明:
localhost:只允许该用户在本地登录,不能远程登录。
%:允许在除本机之外的任何一台机器远程登录。
192.168.0.1:具体的IP表示只允许该用户从特定IP登录