I have a database table that I want all valid MySQL users to have access to (it's for tracking a particular set of statistics across multiple databases). Is there a way to do this?
I know you can wildcard hosts, but you don't appear to be able to wildcard usernames. Essentially, I want to do this:
REVOKE ALL PRIVILEGES ON `database`.`table` FROM ''@'%';
GRANT INSERT, UPDATE ON `database`.`table` TO ''@'%';
MySQL does not support wildcards in user names as per mysql docs and there is no way other than using any script to add additional user privileges each time you add a new user.
Actually the grant statement without any user specified will grant access to the anonymous user account and you will need to set and use the password for the anonymous user account to access the table.
If you are trying to use this in a script I would rather suggest using a separate mysql user to gather information from that table rather than granting privilege & using individual mysql user credentials.
References:
http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-table-privileges
http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
Loop through all MySQL users in
mysql.user
table and grant privileges which you want:UPDATE
As I said in below comment, you can use incron to monitor
/var/lib/mysql/mysql/user.MYI
and run the above script whenever an user is created.Install incron and start it:
Create incron table for
mysql
user:When you create a new MySQL user, you will see the below in
/var/log/cron
:and the new user will be automatically granted
INSERT, UPDATE
privileges ondb.table
:I wonder whether there is a way to get the latest MySQL user and grant privileges for this one instead of doing for all users.