继续前一篇,这里是一些常用的管理命令,也为转载,所有权归原作者所有,此处仅作参考学习.
mysql常用用户管理命令
本机访问权限:
mysql> grant all privileges on *.* to 'username'@'localhost'
-> identified by 'password' with grant option;
远程访问权限:
mysql> grant all privileges on *.* to 'username'@'%'
另外还有一种方法是直接insert into user,注意这种方法之后需要 flush privileges 让服务器重读授权表。
insert into user(host,user,password,ssl_cipher,x509_issuer,x509_subject)
values(‘localhost’,'xff’,password(‘xff’),”,”,”);
flush privileges;
note:1)必须要加上ssl_cipher,x509_issuer,x509_subject三列,以为其默认值不为空(数据库版本为:5.0.51b)
2)flush privileges重载授权表,使权限更改生效
drop user admin@localhost;(@不加默认为“%”)
revoke delete on test.* from admin@'localhost';
grant select,insert,update,delete on *.* to 'admin2′@'%'
identified by ‘admin2′ with grant option;
note:在mysql中,如果@后面的登录范围不同,帐号可以一样
mysql> grant all on customer.* to 'francis'@'localhost'
-> identified by 'frank'
-> with max_queries_per_hour 20
-> max_updates_per_hour 10
-> max_connections_per_hour 5
-> max_user_connections 2;
使用mysqladmin:
shell> mysqladmin -u user_name -h host_name password "newpwd"
或在mysql里执行语句:
mysql> set password for 'username'@'%'
= password('password');
如果只是更改自己的密码,则:
mysql> set password = password(‘password’);
在全局级别使用grant usage语句(在*.*)来指定某个账户的密码:
mysql> grant usage on *.* to 'username'@'%'
identified by 'password';
或直接修改mysql库表:
mysql> update user set password = password('bagel')
-> where host = '%' and user = 'francis';
mysql> flush privileges;
修改root密码:
update mysql.user set password=password(‘passw0rd’) where user=’root’;
mysql> select password('password');
+-------------------------------------------+
| password('password') |
| *2470c0c06dee42fd1618bb99005adca2ec9d1e19 |
1 row in set (0.00 sec)
mysql> select md5('hello');
+----------------------------------+
| md5('hello') |
| 5d41402abc4b2a76b9719d911017c592 |
mysql> select sha1('abc');
-> 'a9993e364706816aba3e25717850c26c9cd0d89d'
sha1()是为字符串算出一个 sha1 160比特检查和,如rfc 3174 (安全散列算法)中所述。
grant select (cur_url,pre_url) on test.abc to admin@localhost;
转载请注明出处:http://www.cnblogs.com/haochuang/