Now that you know how the grant tables work, the final item on the agenda is the mechanics of implementing changes to the tables. MySQL offers two methods of altering access rights in the grant tables - you can either use INSERT, UPDATE and DELETE queries to alter the information in the tables, or use the GRANT and REVOKE commands. Personally, I prefer the former, since it's much easier to understand and remember - although typing in long-winded SQL queries is sometimes a little tedious. Power users would do well to learn GRANT and REVOKE command syntax - details are available in the mySQL manual. For the moment, I'll simply take you through a couple of examples, using both methods, so that you have some insight into the differences between the two methods. The first example sets up a user "tom", password "tommygun", who has permission to access the "recipes" database only from "localhost"
The equivalent GRANT command is:
You could set up an equivalent of the "root" user with
or
It should be noted that privileges set using GRANT and REVOKE are immediately activated; however, privileges set via regular SQL queries require a server reload to come into effect. A server reload can be accomplished via the "mysqladmin" command
or with the
command. And that's about it. I hope you find this information useful, and that you can use it when maintaining your own databases. Ciao!
blog comments powered by Disqus |