摸清一下mysql授权语句的实际执行关系
样例
----------------------------------------------------------------------
grant all PRIVILEGES on db1.* to test@'%' identified by 'test1';
grant all PRIVILEGES on db2.* to test@'%' identified by 'test2';
grant all PRIVILEGES on db3.* to test@'127.0.0.1' identified by 'test3';
grant all PRIVILEGES on db4.* to test@'localhost' identified by 'test4';
flush PRIVILEGES;
------------------------------------------------------------------------
执行后的测试结果
用ip访问时test的密码为test2,能看到的内容是db1,db2
用127.0.0.1访问时test的密码为test4,能看到的内容是db1,db2,db3,db4(说明它权限最大,但是密码会被localhost覆盖)
用localhost访问时test的密码为test4(因为它后执行),能看到的内容是db1,db2,db4(说明localhost还是不能完全替代127.0.0.1的)
另附:%和127.0.0.1的密码是可以不一样的,说明test用户并不是唯一的标识,还是要看后面的连接属性决定