1、创建用户
create user [email protected] identified by ‘password‘;
参数说明:
username:用户名。
host:可以连接的的主机。‘localhost‘表示只能本机连接,‘%‘表示任何一台机器都可以连接,也可以通过ip地址,规定某台远程主机可以连接。
password:连接密码。‘‘表示不需要密码。
例:create user [email protected] identified by ‘123456‘;//只有本地可以连接
create user ‘jerry‘ identified by ‘‘;//任何主机都可以连接,而且不需要密码
2、授权
grant privileges on databasename.tablename
参数说明:
privileges:用户的操作权限 如select update delete insert。如果想拥有所有权限,可以使用all,默认除了grant权限,其他权限都拥有。
databasename:授权的数据库名,表示可以对哪个数据库进行操作。 如果想对所有数据库可以操作,使用*
tablename:授权的表名,表示可以对哪个表进行操作。如果想对所有表可以操作,使用*
例:grand select,insert on *.* [email protected];
grand all on db1.tb1 to [email protected];
grand all on *.* to [email protected];