grant all on *.* to [email protected] identified by "passwd" with grant option 该语句将在user表中为[email protected]创建一个记录,打开所有权限,因为这里是超级用户(全局)权限存储的地方,要用insert语句做同样的事情,语句是:
insert into user values("localhost","anyname",password("passwd"), "y","y","y","y","y","y","y","y","y","y","y","y","y","y") 你可能发现它不工作,这要看你的mysql版本。授权表的结构已经改变而且你在你的user表可能没有14个权限列。用show columns找出你的授权表包含的每个权限列,相应地调整你的insert语句。 下列grant语句也创建一个拥有超级用户身份的用户,但是只有一个单个的权限:
grant reload on *.* to [email protected] identified by "flushpass" 本例的insert语句比前一个简单,它很容易列出列名并只指定一个权限列。所有其它列将设置为缺省的"n":
insert into user (host,password,reload) values("localhost","flush",password("flushpass"),"y") 数据库级权限用一个on db_name.*子句而不是on *.*进行授权:
grant all on sample.* to [email protected] identified by "ruby" 这些权限不是全局的,所以它们不存储在user表中,我们仍然需要在user表中创建一条记录(使得用户能连接),但我们也需要创建一个db表记录记录数据库集权限:
insert into user (host,user,password) values("localhost","boris",password("ruby"))
insert into db values("localhost","sample_db","boris","y","y","y","y","y","y","n","y","y","y")
"n"列是为grant权限;对末尾的一个数据库级具有with grant option的grant语句,你要设置该列为"y"。