Database Reference
In-Depth Information
Connecting as a Different User
Because we are using the GUI logged in as root, we will use the command line MySQL mon-
itor to log in as this user. Open up a dos box, and type the following:
c:
cd \mysql\bin
to get you into the directory with the MySQL executables.
Normally, to run the MySQL monitor you would just type mysql. However, this logs in as
the root user with full access. We need to tell the monitor to log in as our new Mary user. Do
this by typing:
mysql —user=Mary —password=yeti
Now we need to connect to a database within MySQL. Type:
connect mysql
You should now be connected to the database, and all that remains is to have a look at
one of the tables within the database. Type the following to view the user table:
SELECT * FROM user;
Remember that when you are in the MySQL monitor you need to add the semicolon at
the end of the line to make the query execute. We may have got out of the habit of this while
using the graphical client. If you forget to add the semicolon you can just add it to the new
line to trigger the query that you typed on the previous line. Figure 12.4 shows all of the
above in action including a forgotten semicolon.
The table output in Figure 12.4 is a bit messy which is why you may be glad that we nor-
mally use the graphical client. You can, however, see that we have now logged in with our
new user and examined a table. We will now deny the Mary user access to this table using
the graphical client again. Switch back to this, but leave the dos box open so that we can
return to it in a few moments.
Restricting a User's Access
In the graphical client, logged in as root, type:
REVOKE ALL PRIVILEGES ON *.*
FROM Mary@localhost
There is no point in selectively denying access to a table when the user has access to
everything, so the above removes the access anything privilege on the account.
Back at the command prompt, if you select everything from the user table you will still
get the table returned. This is because the REVOKE command just issued is a global com-
mand; it is saying revoke Mary's access to everything. Changes to global privileges only
Search WWH ::




Custom Search