Mysql添加用户来操作指定数据库
创建授权
- 先创用户再授权
新建用户:create user 'username'@'host' identified by 'password';
username
为用户名password
为密码host
如果为localhost
则只能本地登录,使用%
为不限制
授权:grant privileges on databasename.tablename to 'username'@'host';
privileges
为用户的操作权限,可以是 insert,update等等, 官方权限列表
- 创建的时候同时授权
grant privileges on dabasename.* to 'username'@'host' identified by 'password';
实例:grant select,insert,update,delete on ipdata.* to 'ipdata'@'%' identified by '12345465'
ipdata 这个用户可以对 ipdata 数据进行的操作为增删改查,ipdata 用户的密码为12345465
,执行完之后必须刷新权限:flush privileges;
更改用户密码
set password for 'username'@'host'=password('password');
撤销权限
revoke privilege on databasename.tablename from 'username'@'host'
删除用户
drop user 'username'@'host'