-
-
Save liujingyu/75f7548300d6f8c3e06f to your computer and use it in GitHub Desktop.
mysql 位操作(权限使用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 位操作即开始学习计算机就接触的 | |
| 按位与(&): 1&1=1 1&0=0 0&0=0 | |
| 按位或(|):1|1=1 1|0=1 0|0=0 | |
| 按位异或(^):1^1=0 0^0=0 1^0=1 | |
| 这几个运算都支持交换律 | |
| MySQL中也支持这几个位运算,今儿遇到记录用户登录日期一功能需求,设计数据库用一位记录一天,第一位记录1号,第二位记录2号登录,这样可节省数据库存储开支。于是用户在一天内登录多次如何存储,于是想起按位或运算可解决此法,第一次登录更新后,按位或时此位不再更新,好用。 | |
| 记录用户8号有登录。 | |
| insert into USER_LOGIN_12 set sinaid=1686497165,LOGIN=64,MON=2 on duplicate key update login=login|128 ; | |
| 用户权限中常用一位代表一个权限的开启与取消,例如 | |
| 增加某个位上的权限 | |
| update table privliages set priv = priv|N; | |
| N:为对应权限位是1 的的一个十进制数 | |
| 取消某个位上的权限, | |
| update table privliages set priv = priv^N; | |
| N是那个位是1的一个十进制数 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment