mysql> select user,host from mysql.user where user = 'test'; +------+------------+ | user | host | +------+------------+ | test | 172.17.0.2 | | test | 172.17.0.3 | +------+------------+ 2 rows in set (0.01 sec)
-- drop user test@'%'; CREATE USER 'test'@'172.17.0.2' IDENTIFIED BY '123456'; CREATE USER 'test'@'172.17.0.3' IDENTIFIED BY '123456'; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, EXECUTE ON *.* TO 'test'@'172.17.0.2'; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, EXECUTE ON *.* TO 'test'@'172.17.0.3';
> CREATE DEFINER = 'admin'@'localhost' PROCEDURE account_count() > BEGIN > SELECT 'Number of accounts:', COUNT(*) FROM mysql.user; > END; >
The procedure is assigned a DEFINER account of ‘admin’@’localhost’ no matter which user defines it. It executes with the privileges of that account no matter which user invokes it (because the default security characteristic is DEFINER). The procedure succeeds or fails depending on whether invoker has the EXECUTE privilege for it and ‘admin’@’localhost’ has the SELECT privilege for the mysql.user table.