mysqlaccess
mysqlaccess [host[user[database]]] [options]
This utility checks the privileges that a user has for a specific host and database. One use is to run it as a preliminary tool to check for user permissions before proceeding with a customized program that uses one of the APIs.
If MySQL was not installed in the default location for the version
you’re using, you’ll have to set the variable MYSQL
in the mysqlaccess script. Change it with a plain
text editor. Look for the following line (near the beginning) and change
the file path to where the mysql client is
located:
$MYSQL = '/usr/local/mysql/bin/mysql'; # path to mysql executable
With regard to the syntax, the hostname is the first argument and is optional. If not given, localhost is assumed. The username given in the second argument is the name of the user for which the utility is checking privileges. The third argument is the database against which to check privileges. The fourth argument involves several possible options, one of which could be the username by which the utility will access the server to gather information on the user named in the second argument. Here is an example of how you might use this utility:
mysqlaccess localhost marie workrequests -U russell -P
In this example, I give the utility the hostname, then the user
I’m inquiring about, then the database name for which I want user
privilege information. The -U option specifies the
username with which to access the server to gather information. This
user has full access to the mysql database. The
-P instructs the utility to prompt me for a
password.
Here are the results of the preceding inquiry:
Access-rights
for USER 'marie', from HOST 'localhost', to DB 'ANY_NEW_DB'
+-----------------+---+ +-----------------+---+
| Select_priv | Y | | Shutdown_priv | N |
| Insert_priv | N | | Process_priv | N |
| Update_priv | N | | File_priv | N |
| Delete_priv | N | | Grant_priv | N |
| Create_priv | N | | References_priv | N |
| Drop_priv | N | | Index_priv | N |
| Reload_priv | N | | Alter_priv | N |
+-----------------+---+ +-----------------+---+
NOTE: A password is required for user 'reader' :-(
The following rules are used:
db : 'No matching rule'
host : 'Not processed: host-field is not empty in db-table.'
user:'localhost','marie','6ffa06534985249d','Y','N','N','N',
'N','N','N','N','N','N','N','N','N','N'First, a table is presented that displays the privileges for the
combination of the database named, the host given, and the user. This
user has only SELECT privileges.
Additionally, the results are given in raw form for each
component. This user’s privileges are the same for all databases and
hosts (i.e., there are no entries in the db or the
host tables in the mysql
database), so there aren’t any results for those particular components.
For the user component, the command displays details without labels, but
they are presented in the order that they are found in the
user table in the mysql database.
The third field is the password in the encrypted format in which it is
stored. The Ys and Ns are the settings for each user privilege.
Here is a list of options available for this utility in alphabetical order:
--brief, -bThis option provides a brief display of results from an inquiry.
--commitThis option copies grant rules from temporary tables to the grant tables.
--copyThis option reloads temporary tables with original data from the grant tables so that privileges take effect.
--db=database,
-d databaseThis option explicitly specifies the database against which to query the user privileges.
--debug=levelThis option sets the debugging level. The choices are from 0 to 3.
--help, -?This option displays basic help information.
--host=host,
-h hostThis option specifies the host on which to obtain privilege information. The localhost is the default.
--howtoThis option displays basic examples of usage with sample results.
--old-serverThis option stipulates that the server to which the utility
is connecting is running an older version of MySQL (prior to
3.21), requiring a different method with regard to
WHERE clauses in SQL statements.
--password=password,
-p passwordThis option provides the password of the user logging into the server, not the user on which to check for privileges.
--planThis option displays plans for further development of the utility by its developers.
--previewThis option displays the differences in temporary grant tables before they are committed.
--relnotesThis option displays notes on each release of the utility.
--rhost=host,
-H hostIf the utility is not being run on the same server as the MySQL server that’s being queried, use this option to specify the address of the MySQL server to query.
--rollbackThis option undoes the last change to user privileges.
--spassword=password,
-P passwordThis option provides the password when using a superuser.
--superuser=user,
-U userThis option provides a superuser’s username.
--table, -tThis option displays data in an ASCII table format.
--user=user,
-u userThis option provides the username for logging into the server, not the user on which to check for privileges.
--version, -vThis option displays the version of the utility.