Hardware and software setup

Assigning and removing rights. SQL GRANT Commands Revoke Creating and Deleting Users

REVOKE - revoke access rights

Syntax

REVOKE [ GRANT OPTION FOR ] ( ( SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER ) [, ...] | ALL [ PRIVILEGES ] ) ON ( [ TABLE ] table_name[, ...] | ALL TABLES IN SCHEMA schema_name[, ...] ) FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( ( SELECT | INSERT | UPDATE | REFERENCES ) ( column_name[, ...]) [, ...] | ALL [PRIVILEGES] ( column_name[, ...]) ) ON [ TABLE ] table_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( ( USAGE | SELECT | UPDATE ) [, ...] | ALL [ PRIVILEGES ] ) ON ( SEQUENCE sequence_name[, ...] | ALL SEQUENCES IN SCHEMA schema_name[, ...] ) FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( ( CREATE | CONNECT | TEMPORARY | TEMP ) [, ...] | ALL [ PRIVILEGES ] ) ON DATABASE dbname[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( USAGE | ALL [ PRIVILEGES ] ) ON DOMAIN domain name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( USAGE | ALL [ PRIVILEGES ] ) ON FOREIGN DATA WRAPPER foreign_data_wrapper_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( USAGE | ALL [ PRIVILEGES ] ) ON FOREIGN SERVER server_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( EXECUTE | ALL [ PRIVILEGES ] ) ON ( FUNCTION function_name ([ [ argument_mode ] [ argument_name ] argument_type[, ...] ]) [, ...] | ALL FUNCTIONS IN SCHEMA schema_name[, ...] ) FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( USAGE | ALL [ PRIVILEGES ] ) ON LANGUAGE language_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( ( SELECT | UPDATE ) [, ...] | ALL [ PRIVILEGES ] ) ON LARGE OBJECT oid_BO[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( ( CREATE | USAGE ) [, ...] | ALL [ PRIVILEGES ] ) ON SCHEMA schema_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( CREATE | ALL [ PRIVILEGES ] ) ON TABLESPACE tablespace[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] ( USAGE | ALL [ PRIVILEGES ] ) ON TYPE type_name[, ...] FROM ( [ GROUP ] role_name| PUBLIC ) [, ...] [ CASCADE | RESTRICT] REVOKE [ ADMIN OPTION FOR ] role_name[, ...] FROM role_name[, ...] [ CASCADE | RESTRICT]

Description

The REVOKE command revokes one or more roles of the rights previously assigned. The PUBLIC keyword denotes an implicitly defined group of all roles.

Note that any particular role gets the sum of the rights given to it directly, the rights given to any role it is included in, and the rights given to the PUBLIC group. Therefore, for example, depriving PUBLIC of the SELECT right will not necessarily mean that all roles will lose the SELECT right for this object: it will be preserved for those roles to which it was granted directly or indirectly, through another role. Similarly, removing the SELECT right from a user may not affect that user's ability to use the SELECT right if that right is granted to the PUBLIC group or other role in which they are included.

If GRANT OPTION FOR is specified, only the right to grant the right is revoked, not the right itself. Without this instruction, both the right and the right to dispose of it are revoked.

If a user has a transferable right and has given it to other users, the last right is considered dependent. When the first user loses the right itself or the transfer right and there are dependent rights, those dependent rights are also revoked if CASCADE is additionally specified; in otherwise the operation fails. This recursive revoking only affects privileges acquired through a chain of users that can be traced back to the user that is the subject of the REVOKE command. Thus, users may end up retaining this right if it was also obtained through other users.

When a table access right is revoked, the corresponding rights for each column of the table (if such rights are set) are automatically revoked along with it. On the other hand, if a role has been granted permissions on a table, revoking the role of the same permissions at the individual column level has no effect.

When a user is removed from the role, GRANT OPTION changes to ADMIN OPTION , otherwise the behavior of the command is similar. Note also that this form of the command does not accept the redundant word GROUP .

Remarks

To view the permissions assigned to existing tables and columns, you can use the \dp command in psql. Its output format is discussed in the description of GRANT . For other, non-table objects, other \d commands are provided, which can show, among other things, the rights assigned to them.

A user can only revoke the rights that he has given to another directly. If, for example, user A has given a transferable right to user B, and user B has in turn given that right to user C, then user A cannot revoke that right directly to C. Instead, user A can revoke the transferable right to user C. B and use the CASCADE parameter so that user C loses this right along the chain. Or, for example, if both A and B granted the same right to C, then A will be able to revoke the right that he gave, but not user B, so that as a result C will still have that right.

If someone other than the owner of the object attempts to revoke access to an object (using REVOKE), the command will fail if the user does not have any rights to the object. If the user has some rights, the command will be executed, but the user will be able to revoke only those rights that are given to him with the right to dispose of them. REVOKE ALL PRIVILEGES forms will issue a warning if the user does not have such rights at all, while other forms will issue warnings if the user does not have the right to control exactly the rights specified in the command. (In principle, these statements also apply to the owner of the object, but he is allowed to dispose of all the rights, so such situations are impossible.)

If a GRANT or REVOKE command is issued by a superuser, the command is executed as if it were the owner of the affected object. Since all rights ultimately emanate from the owner of the object (perhaps indirectly through a chain or through a right by right), the superuser can revoke all rights, but this may require the use of CASCADE mode, as described above.

REVOKE can also be performed by a role that is not the owner of the given object, but is a member of the owning role, or a member of a role that has WITH GRANT OPTION rights on that object. In this case, the command will be executed as if it were executed by the containing role, who actually owns the object, or has WITH GRANT OPTION rights. For example, if table t1 is owned by role g1 , of which role u1 is a member, then u1 can revoke the rights to use t1 that are written as given by role g1 . This may include rights granted by the role u1 , as well as other members of the role g1 .

If the role that is executing the REVOKE command has obtained the specified rights indirectly through more than one role membership path, which role will be chosen to run the command is undefined. In such cases, it is recommended to use the SET ROLE command and switch to the role you want to see as the REVOKE executor. If this is not done, the rights may not be revoked as planned, or the rights may not be revoked at all.

Examples

Depriving the public group of the right to add data to the films table:

REVOKE INSERT ON films FROM PUBLIC;

Revoke the user manuel of all rights to the kinds view:

REVOKE ALL PRIVILEGES ON kinds FROM manuel;

Note what this actually means « take away all the rights that I gave» .

Exclude members of the admins role of user joe:

REVOKE admins FROM joe;

Compatibility

The compatibility notes given for the GRANT command also apply to REVOKE . The standard requires mandatory indication keyword RESTRICT or CASCADE , but PostgreSQL implies RESTRICT by default.

By default, the account does not have any rights in the Oracle database. You can't even create connections without rights assigned. And even after gaining connection rights, the account cannot do anything useful (or dangerous) without gaining the appropriate rights. Permissions are granted with the GRANT command and removed with the REVOKE command. Additional command directives are used to allow an account to share the rights it has with other users. By default, only the administrator accounts (SYS and SYSTEM) have permissions to assign rights. The user who assigns the rights to another user is called a grantor when the recipient of the rights is a grantee. Rights are divided into two groups: system rights, which roughly speaking allow the user to perform actions that affect the data dictionary, and rights over objects, which allow the user to perform actions that affect data.

System rights

In total, about two hundred system rights are available. Most of them affect actions that affect the wording of data (such as creating tables or users). The rest affect the instance or the database (creating tablespaces, changing database parameters and creating sessions). The most commonly used rights are

  • CREATESESSION - connection rights. Without these rights, you won't even be able to connect to the database
  • RESTRICTEDSESSION - If the database is started with the STARTUPRESTRICT directive or the ALTERSYSTEMENABLERESTRICTEDSESSION command is used, then only users with these rights will be able to connect to the database
  • ALTERDATABASE - allows you to execute commands that affect physical structures
  • ALTERSYSTEM - allows you to change instance parameters and memory structure
  • CREATETABLESPACE - together with ALTERTABLESPACE and DROPTABLESPACE allow the user to manipulate tablespaces
  • CREATETABLE - allows gratee to create tables in his schema; includes the ability to create, modify, and drop tables, execute DML and select commands, and manage indexes
  • GRANTANYOBJECTPRIVILEGE - allows the grantee to manage the rights of objects that do not belong to him, but does not give rights to himself
  • CREATEANYTABLE - grantee can create tables that belong to other accounts
  • DROPANYTABLE – grantee is allowed to drop tables that belong to other accounts
  • INSERTANYTABLE, UPDATEANYTABLE, DELETEANYTABLE - gives the grantee the right to execute DML commands on objects that do not belong to him
  • SELECTANYTABLE - Gives the grantee the right to SELECT on any table.

Syntax for assigning permissions

GRANT privilege [,privilege…] TO username;

After creating an account, it is usually assigned permissions frequently used by users who are involved in the development of the application

grant create session, alter session,

create table, create view, create synonym, create cluster,

create database link, create sequence,

create trigger, create type, create procedure, create operator

to username;

These rights allow you to connect and set up a session, create objects, and store PL/SQL objects. Objects can only be created in the account schema; no rights to schemes of other accounts. Also, object creation is limited by tablespace limits.

Another option for assigning rights would be to assign grantee access to reassign rights to other accounts. for example

connect system/oracle;

grant create table to scott with admin option;

connect scott/tiger;

grant create table to jon;

Executing these commands will allow SCOTT to create tables in its own schema and execute the GRANT command. SCOTT grants the JON user permission to create tables - but JON will only be able to create tables in the JON schema. Figure 6-5 shows the user rights in the Database Control; the same information can be obtained by querying the DBA_SYS_PRIVS view.

If system permissions are revoked, everything you did while you had permissions remains in effect. If you had rights with ADMIN OPTION, then all users to whom you assigned rights - the rights remain, despite the fact that your rights have been revoked. There is no record of who exactly assigned system privileges, so it is impossible to take away CASCADE rights as shown in Figure 6-6

Revocation of a system privilege will not cascade (unlike

revocation of an object privilege).

ANY rights give access to all objects in the database. Thus

grant select any table to scott

allow the SCOTT account to execute a SELECT query against all tables in all database schemas. This assignment of rights is considered bad manners and ANY rights are only assigned by the DBA.

In fact, ANY is not as dangerous now as with earlier releases. It no longer

includes tables in the SYS schema, so the data dictionary is still protected. But

ANY should still be used with extreme caution, as it removes all protection

from user tables.

Object rights

Object rights give access to execute DML and SELECT commands on the corresponding objects and execute PL/SQL objects. These rights do not exist for objects in the account schema; if the user has the CREATE TABLE system rights, this means that he can execute SELECT and DML queries on the tables he created without additional rights.

The ANY privileges that grant permissions against objects in

every user account in the database, are not object privileges-they are

system privileges.

Object rights apply to different groups of objects

Command syntax

GRANT privilege ON object TO username ;

for example

You can use ALL to apply permissions for all operations, or you can use a specific table or view column specification.

grant select on store.orders to scott;

grant update(order_status) on store.orders to scott;

grant all on store.regions to scott;

These commands will allow the SCOTT account to execute a SELECT query against all columns of the ORDERS table in the STORE schema, but update the data in only one column. The SCOTT account also has access to all transactions in the REGIONS table. Figure 6-7 shows the result of assigning permissions when viewed in the Database Control

Granting privileges at the column level is often said to be bad practice

because of the massive workload involved. If it is necessary to restrict people'

access to certain columns, creating a view that shows only those columns will

often be a better alternative.

Using the WITH GRANT OPTION directive will allow the user to transfer their rights to other accounts. Oracle stores information about who gave access to whom at the object level; this allows you to revoke rights given this information. Consider an example

connect store/admin123;

grant select on customers to sales with grant option;

connect sales/sales;

grant select on store.customers to webapp with grant option;

connwebapp/oracle;

grant select on store.customers to scott;

connect store/admin123;

revoke select on customers from sales;

After executing these commands, neither the SALES user nor the WEBAPP user nor the SCOTT user has the right to execute SELECT commands on the STORE.CUSTOMERS table.

Revocation of an object privilege will cascade (unlike revocation of

GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...] ON (tbl_name | * | *.* | db_name.*) TO user_name "password"] [, user_name ...] ] ] ] ] REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...] ON (tbl_name | * | *.* | db_name.*) FROM user_name [, user_name ...]

GRANT has been included in MySQL since version 3.22.11 and up. In earlier versions of MySQL, the GRANT statement does nothing.

The GRANT and REVOKE commands allow system administrators create MySQL users, and grant or revoke rights to users at four levels of privileges:

Global level Global privileges apply to all databases on the specified server. These privileges are stored in the mysql.user table. Database layer Database privileges apply to all tables in the specified database. These privileges are stored in the mysql.db and mysql.host tables. Table level Table privileges apply to all columns of the specified table. These privileges are stored in the mysql.tables_priv table. Column level Column privileges apply to individual columns of the specified table. These privileges are stored in the mysql.columns_priv table.

If privileges are granted to a user that does not exist, then that user is created. See section 4.3.5 Adding New Users to MySQL for examples of how the GRANT command works.

The table lists the possible values ​​for the priv_type parameter for GRANT and REVOKE statements:

ALLSets all simple privileges except WITH GRANT OPTION
ALTERAllows the use of ALTER TABLE
CREATEAllows the use of CREATE TABLE
CREATE TEMPORARY TABLESEnables the use of CREATE TEMPORARY TABLE
DELETEAllows use of DELETE
DROPAllows the use of DROP TABLE .
EXECUTEAllows the user to run stored procedures (for MySQL 5.0)
FILEAllows the use of SELECT ... INTO OUTFILE and LOAD DATA INFILE .
INDEXEnables the use of CREATE INDEX and DROP INDEX
INSERTAllows the use of INSERT
LOCK TABLESAllows use of LOCK TABLES on tables that have the SELECT privilege.
PROCESSAllows the use of SHOW FULL PROCESSLIST
REFERENCESReserved for future use
RELOADAllows the use of FLUSH
REPLICATION CLIENTGrants the user the right to query the location of the parent and slave servers.
REPLICATION SLAVERequired for slave servers during replication (to read information from the binary logs of the parent server).
SELECTAllows the use of SELECT
SHOW DATABASESSHOW DATABASES displays all databases.
SHUTDOWNAllows the use of mysqladmin shutdown
SUPERAllows one connection to be established (one time), even if max_connections is reached, and to run CHANGE MASTER , KILL thread , mysqladmin debug , PURGE MASTER LOGS and SET GLOBAL commands
UPDATEAllows the use of UPDATE
USAGESynonym for ``without privileges''.

The USAGE value can be set if you want to create a user without privileges.

The CREATE TEMPORARY TABLES , EXECUTE , LOCK TABLES , REPLICATION ... , SHOW DATABASES , and SUPER privileges are new in version 4.0.2. To use these new privileges after upgrading to version 4.0.2, you must run the mysql_fix_privilege_tables script.

In older versions of MySQL, the PROCESS privilege grants the same rights as the new SUPER privilege.

To revoke a user's privileges granted by the GRANT command, use the priv_type value in the GRANT OPTION:

Mysql> REVOKE GRANT OPTION ON ... FROM ...;

Only the following priv_type values ​​can be specified for a table: SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , GRANT , I NDEX , and ALTER .

The only priv_type values ​​that can be specified for a column (when using the column_list statement): SELECT , INSERT , and UPDATE .

Global privileges can be set using the ON *.* syntax, and database privileges can be set using the ON db_name.* syntax. If you specify ON * while the current database is open, then the privileges will be set for this database. ( A warning: if you specify ON * when absence open current database, this will affect global privileges!)

In order to be able to define permissions for users from specific computers, MySQL provides the ability to specify a username (user_name) in the form . If you want to specify a user string that contains special characters (such as `-") or a host string that contains special or wildcard characters (such as `%"), you can enclose the name remote computer or the user in quotes (for example, "test-user"@"test-hostname").

You can also use wildcard characters in the remote computer name. For example, "%.loc.gov" refers to the user of all remote computers in the loc.gov domain, and "144.155.166.%" refers to the user of all remote computers on subnet 144.155.166 class C.

The simple form user is a synonym for "%" .

MySQL does not support wildcards in usernames. Anonymous users are defined by inserting User="" records into the mysql.user table or by creating a user with an empty name using the GRANT command.

Note: if anonymous users is allowed to connect to the MySQL server, you must also grant privileges to all local users as local computer the mysql.user table will use the login for the anonymous user!

To check if this is happening on your computer, run the following query:

mysql> SELECT Host,User FROM mysql.user WHERE User="";

On the this moment the GRANT command supports remote computer, table, database, and column names with a maximum of 60 characters. The username must contain no more than 16 characters.

Privileges for a table or column are formed using the logical OR operator from the privileges of each of the four levels. For example, if the mysql.user table specifies that the user has the global SELECT privilege, that privilege is not revoked at the database, table, or column level.

The privileges for a column can be calculated as follows:

Global privileges OR (database privileges AND remote computer privileges) OR table privileges OR column privileges

In most cases, user rights are defined at only one privilege level, so this procedure is usually not as complicated as described above. detailed information the sequence of steps for checking privileges is presented in section 4.2 General Security Issues and the MySQL Access Privilege System.

If privileges are granted to a user/remote machine combination that is not in the mysql.user table, then an entry is added to the latter and remains in the table until it is removed with the DELETE command. In other words, the GRANT command can create user records in the table, but the REVOKE command cannot delete them. This must be done with the DELETE command.

If you have database privileges, an entry is created in the mysql.db table as needed. This entry is removed when all privileges on this database are removed with the REVOKE command.

If the user does not have any privileges on the table, then the table is not displayed when the user requests a list of tables (for example, using the SHOW TABLES statement).

The WITH GRANT OPTION statement gives the user the ability to grant other users any privileges they themselves have at the specified privilege level. Care must be taken when granting the GRANT privilege, because two users with different privileges can combine their privileges!

The MAX_QUERIES_PER_HOUR # , MAX_UPDATES_PER_HOUR # and MAX_CONNECTIONS_PER_HOUR # options are new in MySQL versions 4.0.2. These settings limit the number of requests, updates, and logins a user can make in one hour. If set to 0 (default), it means that there are no restrictions for this user. See section.

You cannot grant another user a privilege that you do not have yourself. The GRANT privilege allows you to grant only those privileges that you have.

Note that if a user is assigned the GRANT privilege at a particular privilege level, then all privileges that the user already has (or will be granted in the future!) at that level can also be granted by that user. Suppose a user has been granted the INSERT privilege on a database. If you then grant the SELECT privilege on the database and specify WITH GRANT OPTION , the user will be able to grant not only the SELECT privilege but also INSERT . If you then grant the user the UPDATE privilege on the database, the user can then assign INSERT , SELECT , and UPDATE .

ALTER privileges should not be granted to regular users. This gives the user the ability to break the privilege system by renaming tables!

Note that if table or column privileges are used, even for one user, the server checks table and column privileges for all users, and this slows down MySQL somewhat.

When mysqld is started, all privileges are read into memory. Database, table, and column privileges take effect immediately, while user-level privileges take effect the next time the user connects. Changes to privilege assignment tables that are made using the GRANT and REVOKE commands are processed by the server immediately. If you modify privilege assignment tables manually (using INSERT , UPDATE , etc.), you must run a FLUSH PRIVILEGES or mysqladmin flush-privilege s statement to instruct the server to reload the privilege assignment tables. See section 4.3.3 When changes to privileges take effect.

The most significant differences between the ANSI SQL and MySQL versions of the GRANT command are as follows:

  • In MySQL, privileges are assigned to the combination username + remote computer, not just the username.
  • ANSI SQL lacks global and database-level privileges, and ANSI SQL does not support all MySQL privilege types. In turn, MySQL lacks support for the ANSI SQL TRIGGER , EXECUTE , or UNDER privileges.
  • The ANSI SQL privilege structure is hierarchical. If you delete a user, all privileges assigned to that user will be revoked. In MySQL, assigned privileges are not automatically revoked, they must be removed if necessary.
  • In MySQL, a user can use an INSERT statement on a table if they have the INSERT privilege on only a few columns in that table. Columns that do not have the INSERT privilege will be set to their default values. ANSI SQL requires the INSERT privilege on all columns.
  • When you drop a table in ANSI SQL, all privileges on that table will be revoked. If you revoke a privilege in ANSI SQL, then all privileges that were granted based on that privilege will also be revoked. In MySQL, privileges can only be removed using the REVOKE command or by changing the MySQL privilege assignment tables.

For a description of the use of REQUIRE , see See section 4.3.9 Using secure connections .

User Comments

Posted by Frank Wortner[Delete][Edit]

I had no problems with ld. DEC (Compaq) might
have fixed ld in a patch kit. You might want to
install the latest patch kit for your Digital Unix
(Tru64 Unix) before building MySQL. patch kits
are available at
href=http://ftp.support.compaq.com/public/unix/ >
http://ftp.support.compaq.com/public/unix/

Posted by on Saturday February 16, 2002, @10:21pm[Delete][Edit]

For source installations, these instructions refer to the directory structure presuming "usr/local" was used (default) with configure. But the preceding page's instructions (for compilation/installation) suggest you use:

./configure --prefix=/usr/local/mysql

To be consistent (and this is causing me some hassles with Perl, so it's not purely semantic), the instructions on this page should presume /usr/local/mysql was specified as the installation directory with configure.

Posted by Linda Wright on Saturday February 16, 2002, @10:21pm[Delete][Edit]

This is probably the most important and least
appreciated sections of all of the mySQL
documentation for first time mySQL users. IMHO
reading this page in conjunction with
http://www.mysql.com/doc/P/r/Privileges.html is a
must for anyone planning secure database systems
of any real sophistication.

Posted by Christopher Raymond on Saturday February 16 2002, @10:21pm[Delete][Edit]

I am trying to install MySQL under OS X public beta. When I run the mysql_install_db script, I get an error message:

Dyld: ./bin/mysqld can't open library: /usr/lib/libpthread.A.dylib (No such file or directory, errno = 2)
Installation of grant tables failed!

I am assuming that the script is looking for a directory that doesn't exist because Apple has a little bit different directory naming structure. Maybe this script needs to be modified for the OS X distribution.

Can anyone help?

Posted by Mark Zieg on Saturday February 16 2002, @10:21pm[Delete][Edit]

It would be nice if there was an option to log connections, but not queries.

Posted by Bennett Haselton on Saturday February 16, 2002, @10:21pm[Delete][Edit]

If you"re logged on as the mysql root user, without a current database selected, and you try to
grant all privileges to a user with the command:

GRANT ALL PRIVILEGES ON *TO bhaselto

Then the RELOAD, SHUTDOWN, PROCESS, FILE and GRANT will not be granted, as can be
verified by checking the "user" table of the "mysql" database. (This is presumably by design,
since these privileges can make a user "too powerful".)

Posted by DC Hill on Saturday February 16 2002, @10:21pm[Delete][Edit]

NOTE: If you have granted privileges to a user on a particular database, or at any lower level than that, invoking "REVOKE ALL ON *.* FROM ;" will NOT revoke privileges at those levels. The *.* in the above statement means "global", not "all (individual) tables on all (individual) databases. That statment will ONLY revoke global privileges, as stored in the mysql.user table. You MUST revoke any more specific privileges in the same as they were granted, if you wish them to be removed from the privilege manner tables.(i.e. - GRANT ALL ON foo.* TO ; => REVOKE ALL ON foo.* FROM ;) I hope this saves some of you a little time and frustration.

Posted by Cris Perdue on Saturday February 16, 2002, @10:21pm[Delete][Edit]

"If you have the process privilege, you can see
all threads.
Otherwise, you can only see your own threads."

Posted by FreeBSD Forums on Saturday February 16 2002, @10:21pm[Delete][Edit]

You can use phpMyAdmin web based tool to do a lot
of mySQL admin functions. href="http://www.freebsdforums.org"
>FreeBSD forums

Posted by on Monday February 25, 2002, @6:03am[Delete][Edit]

Verified on MySQL 3.23.36 on Red Hat Linux 7.1:
Note that if you type
use a_c;
grant select on * to ;
you will have given access to any
database matching "a_c" where the underscore is a
wild card. (Rarely a problem, I suppose).
Rectify with
update mysql.db set db="a\_c" where db="a_c";

Posted by jan behrens on Tuesday July 9, 2002, @1:31am[Delete][Edit]

the aformentioned bug from DAN ELIN in x.x.41 is
apperently still valid in x.x.51,i cannot logon to a
database after GRANTing privileges and given a
password to a new user(yes, i flushed
privileges)..................only root access is possible

Posted by Dan Egli on Thursday April 4 2002, @8:33pm[Delete][Edit]

There seems to be a bug in 3.23.41 using Grant.
Only root can access the mysql database, even
after using Grant to grant privs on whatever
database/table/column/ect.. you always get
permission denied, regardless.

Posted by Lars Aronsson on Saturday June 8 2002, @11:16am["%". When I try to delete them I"m told certian database, but no global privileges, the
CREATE TEMPORARY TABLE privilege on that database
is denied.

You have to give global CREATE __and__ global
CREATE TEMPORARY TABLES to the user. IOW:
GRANT CREATE, CREATE TEMPORARY TABLES ON *.* TO
;

Needless to say, this affects security gracely.

Posted by on Sunday August 25 2002, @9:17am[Delete][Edit]

Temporary files are a great idea but even with
Create and Create Temproary File rights in the
user (global rights) file it still doesn't work.
This appears to be badly designed.

Posted by Brad Bulger on Monday September 2, 2002, @4:09am[Delete][Edit]

It should be noted that WITH GRANT OPTION only
allows the user to pass on privileges to users who
already exist. The automagical creation of user
records does not apply - you get an error saying
that the user with the GRANT OPTION privilege does
not have access to the "mysql" database. This is
probably a good thing, but it needs to be documented.

Posted by Michael Babcock on Friday November 8 2002, @1:00pm[Delete][Edit]

SHOW MASTER STATUS requires PROCESS privileges.
Other such odd combinations should be documented.

Posted by Dee Kintaudi on Thursday November 21 2002, @12:42pm[Delete][Edit]

Okay I got a question and a problem with MySQL and
passwords:). I tried to use several of the options
and most of them have not worked. However one
soloution did work and I tested it out twice and it
was solid. Of course I lost the little piece of paper I
wrote it out on and I can't seem to find this
solotion anywhere, as if it did not exist or maybe I
imagined it. The solution that worked for me
before I lost the little slip of paper I wrote it down on
goes something like this..... insert into user root
Password "my password" and then something
with "Y", "Y", "Y", (about a dozen or 15 times or so)
However, I can't find this soloution anywhere can
someone help me out here?

I think it would be so nice if they just put this
throughout their documentation instead of trying to
hide it. I think this would solve many problems. Just
put password = "Y", "Y", "Y", its like their ashamed of it
or something.

Posted by AJIT DIXIT on Monday November 25 2002, @6:56am[Delete][Edit]

When I work on multi-table update with root user
it works fine

When I work with non-root user I get error

Sql: update Stockists, areas set a_nm = aname
where acd = area

DCL commands are used to secure databases in an environment with multiple user databases. The two types of DCL commands are grant and revoke. Only the database administrator or database object owner can grant/remove privileges on a database object.

SQL GRANT Command

SQL GRANT is a command used to grant access or privileges on database objects to users.

The syntax of the GRANT command is:

GRANT privilege_name
ON object_name
TO (user_name |PUBLIC |role_name)
;

  • PRIVILEGE_NAME this access right or privilege is granted to the user. Some of the access rights are ALL, EXECUTE and SELECT.
  • object_name is the name of a database object like a table, a view, and a SEQUENCE stored procedure.
  • username
  • username this is the username to which access the right to be taken for granted.
  • PUBLIC used to grant access rights to all users.
  • ROLES are a set of privileges grouped together.
  • WITH GRANT OPTION - Allows a user to grant access rights to other users.

For example: EMPLOYEE GRANT TO CHOICE FOR user1; This command grants SELECT permission on the employee table to user1. You should use it with the GRANT option carefully because, for example, if you grant SELECT privilege on the employee table to user1 using the WITH GRANT option, then user1 can grant the SELECT privilege on the table employee to another user, such as user2, etc. Later, if you revoke the SELECT privilege on the employee from user1, user2 will still have the SELECT privilege on the employee table.

SQL REVOKE Command:

The REVOKE command removes user access rights or privileges on database objects.

The syntax of the REVOKE command is:

REVOKE privilege_name
ON object_name
FROM (user_name |PUBLIC |role_name)

For example: KEWOKE SELECT ON employee user1; This command will revoke the SELECT privilege on the employee's table from user1. When you REVOKE SELECT the privilege on the table from the user, the user will no longer be able to select data from that table. However, if a user has been granted SELECT privileges on that table from more than one user, he/she can select from that table until everyone who has received permission revokes it. You cannot revoke privileges if they were not originally granted by you.

Privileges and Roles:

Privileges: Access rights defines the access rights granted to the user on the database object. There are two types of privileges.

privileges 1) System- It allows the user to create, modify or delete database objects.
2) Object Privileges- This allows the user to EXECUTE, SELECT, INSERT, UPDATE or DELETE data from database objects to which privileges apply.

Few create system privileges are listed below:

System Privileges Description
CREATE object allows users to create the specified object in their own schema.
CREATE ANY object allows users to create the specified object in any schema.

The above rules also apply for Altera and DROP system privileges.

Few of the object privileges are listed below:

Object Privileges Description
INSERT allows users to insert rows into a table.
SELECT allows users to select data from a database object.
UPDATE allows user to update data in a table.
EXECUTE allows user to execute a stored procedure or a function.

Roles: Roles are a set of privileges or access rights. When there are many users in the database it becomes difficult to grant or revoke privileges to users. Therefore, if you have defined roles, you can grant or revoke privileges to users, thereby automatically granting or revoking privileges. You can either create roles or use predefined oracle system roles.

Some of the privileges granted to system roles are as follows:

System Role Privileges Granted to the Role
CONNECT CREATE TABLE, CREATE VIEW, CREATE SYNONYM, CREATE SEQUENCE, CREATE SESSION etc.
RESOURCE CREATE PROCEDURE, CREATE SEQUENCE, CREATE TABLE, CREATE TRIGGER etc. The primary usage of the RESOURCE role is to restrict access to database objects.
DBA ALL SYSTEM PRIVILEGES

Create roles:

The syntax for creating a role is:

CREATE ROLE role_name
;

For example: To create a role called 'developer' with password as 'PWD' the code would be as follows

CREATE ROLE testing
;

It is easier to grant or revoke privileges to users through roles rather than assigning privileges directly to each user. If a role is identified with a password, then when you grant or revoke privileges to a role, you must be sure to identify it with a password.

We can grant or revoke a role privilege as shown below.

For example: To grant the CREATE TABLE privilege to a user by creating a test role:

First, create a testing role

CREATE ROLE testing

Second, grant the CREATE TABLE privilege to test the role. You can add additional privileges to this role.

GRANT CREATE TABLE TO testing;

Third, grant the user a role.

GRANT testing TO user1;

To revoke the CREATE TABLE privilege from testing a ROLE, you can write:

REVOKE CREATE TABLE FROM testing;

The syntax to drop a role from the database is as below:

DROP ROLE role_name;

For example: To remove a role called developer, you can write.

Liked the article? Share with friends!
Was this article helpful?
Yes
Not
Thanks for your feedback!
Something went wrong and your vote was not counted.
Thank you. Your message has been sent
Did you find an error in the text?
Select it, click Ctrl+Enter and we'll fix it!