Mysql下建立用户授权权限例子
来源: 阅读:788 次 日期:2015-03-10 16:10:12
温馨提示: 小编为您整理了“Mysql下建立用户授权权限例子”,方便广大网友查阅!

用户授权在mysql中使用grant命令就可以了,我相信各位都会有了解过了,下面小编为各位介绍一个Mysql下建立用户授权权限例子,希望本文章对各位有帮助.

建立用户,授权数据库:

mysql> create user identified by 'admin123'; #建立主机为localhost,密码为admin123的用户byrd

Query OK, 0 rows affected (0.05 sec)

mysql> show grants for ; #查看byrd权限,USAGE表示连接权限

+-------------------------------------------------------------------------------------------------------------+

| Grants for |

+-------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |

+-------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | ::1 |

| root | lamp |

| byrd | localhost |

| root | localhost |

+------+-----------+

5 rows in set (0.00 sec)

mysql> grant all on gbk.* to; #用户byrd、主机localhost对数据库gbk拥有所有权限

Query OK, 0 rows affected (0.01 sec)

mysql> show mysqls for ;

+-------------------------------------------------------------------------------------------------------------+

| Grants for |

+-------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |

| GRANT ALL PRIVILEGES ON `gbk`.* TO |

+-------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

mysql> flush privileges;

mysql> grant all on gbk.* to identified by 'admin123'; #建立用户test,用户gbk数据库所有权限,同上

mysql> show grants for ;

+-------------------------------------------------------------------------------------------------------------+

| Grants for |

+-------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |

| GRANT ALL PRIVILEGES ON `gbk`.* TO|

+-------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

远程连接同上:

mysql> grant all on gbk.* to 授权可连接主机' identified by 'admin123'; #这是Server端

[root@lamp ~]# /usr/local/mysql/bin/mysql -uroot -p'admin123' -h hk.t4x.org #这是client端

补充:ALL PRIVILEGES权限包括:

mysql> show grants for ;

+-------------------------------------------------------------------------------------------------------------+

| Grants for |

+-------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |

| GRANT ALL PRIVILEGES ON `gbk`.* TO |

+-------------------------------------------------------------------------------------------------------------+

mysql> revoke insert on `gbk`.* from ;

Query OK, 0 rows affected (0.00 sec)

mysql> show grants for ;

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Grants for |

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO IDENTIFIED BY PASSWORD '*01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C' |

| GRANT SELECT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `gbk`.* TO |

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

ALL PRIVILEGES权限包括:GRANT SELECT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT,insert

更多信息请查看IT技术专栏

更多信息请查看网络编程
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map