MySQL的Grant命令

Grant 添加 MySql 用户
2009-04-03 14:40

我安装的版本:

MySQL> select version();
+————+
| version()   |
+————+
| 5.0.22-log |
+————+
1 row in set (0.05 sec)

添加用户:

mysql> grant select,update,insert,delete on *.* to jimmy@AS3 identified by “jimmy”;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from user;
+———–+——–+——————————————-+
| host       | user    | password                                   |
+———–+——–+——————————————-+
| localhost | root    |                                            |
| AS3        | root    |                                            |
| AS3        |         |                                            |
| localhost |         |                                            |
| AS3        | yuanjl | 550185cd02026208                           |
| localhost | yuanjl | 550185cd02026208                           |
| AS3        | jimmy   | *1E7F320B8F580AADC02E8A70285E46A8CFDA3359 |
+———–+——–+——————————————-+
7 rows in set (0.00 sec)

mysql> quit
Bye
[root@AS3 mysql-5.0.22]# mysql -pjimmy -u jimmy -h AS3 mysql
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
[root@AS3 mysql-5.0.22]# mysql -u root -h AS3 mysql
Welcome to the MySQL monitor.   Commands end with ; or /g.
Your MySQL connection id is 36 to server version: 5.0.22-log

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql> update user set password=old_password(‘jimmy’) where user=’jimmy’ and host=’AS3′;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1   Changed: 1   Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@AS3 mysql-5.0.22]# mysql -pjimmy -u jimmy -h AS3 mysql
Welcome to the MySQL monitor.   Commands end with ; or /g.
Your MySQL connection id is 37 to server version: 5.0.22-log

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql>

 

 

2、Mysql添加用户

个人教训,在添加Mysql帐号的时候,一定要主义用户名和主机(local和%)均要被引号引起,否则命令即错

命令方式的.注意每行后边都跟个 ; 表示一个命令语句结束.

格式:grant select on 数据库.* to “用户名”@“登录主机” identified by “密码”;