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 "密码";



例1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MYSQL,然后键入以下命令:

grant select,insert,update,delete on *.* to “test1”@"%" Identified by "abc"; 



补充所有权限语句:

由例1得: 将执行权限(select,insert,....)改为all privileges,即表示拥有所有权限,包括创建数据库权限,删除数据库,已经不局限于在一个数据库内操作

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'; 



例1(非补充)中增加的用户是十分危险的,因为你的主机是%,%即代表任意位置的主机,而local即词义"本地",假如,某个人想知道test1的密 码,那么他就可以在internet上的任何一台电脑上连接到你的mysql数据库并对你的数据可以为所欲为了,解决办法见例2。



根据例1补充语句,此语句尽量不要在Mysql服务器上使用,如果你的服务器处于托管或远端地带,如果你需要远程管理Mysql服务器,而由不想通过超级 终端登录到服务器上,那么你只好用此语句,但要清楚一件事,即你能使用此方法连接服务器,其他人也可以,所以要保管好你的mysql密码



例2、 增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作 (localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据 库,只能通过MYSQL主机上的web页来访问了。 



grant select,insert,update,delete on mydb.* to “test2”@localhost identified by "abc";

如果你不想test2有密码,可以再打一个命令将密码消掉。

grant select,insert,update,delete on mydb.* to “test2”@localhost identified by "";



grant select,insert,update,delete on dez.* to “test2”@"%" identified by "123456";
 
 
 
---------------------------
 
cmd下连接mysql: 
mysql -uroot -p 回车 注意密码不要打在-p后面

相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2021-08-25
  • 2021-08-04
  • 2022-03-03
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案