- MySQL 5.1 Reference Manual :: 5 MySQL Server Administration :: 5.4 The MySQL Access Privilege System :: 5.4.1 Privileges Provided by MySQL
-
- MySQL 5.1 Reference Manual
- Preface, Notes, Licenses
- 1 General Information
- 2 Installing and Upgrading MySQL
- 3 Tutorial
- 4 MySQL Programs
- 5 MySQL Server Administration
- 6 Backup and Recovery
- 7 Optimization
- 8 Language Structure
- 9 Internationalization and Localization
- 10 Data Types
- 11 Functions and Operators
- 12 SQL Statement Syntax
- 13 Storage Engines
- 14 High Availability and Scalability
- 15 MySQL Enterprise Monitor
- 16 Replication
- 17 MySQL Cluster NDB 6.X/7.X
- 18 Partitioning
- 19 Stored Programs and Views
- 20 INFORMATION_SCHEMA Tables
- 21 Connectors and APIs
- 22 Extending MySQL
- A MySQL 5.1 Frequently Asked Questions
- B Errors, Error Codes, and Common Problems
- C MySQL Change History
- D Restrictions and Limits
- Index
- Standard Index
- C Function Index
- Command Index
- Function Index
- INFORMATION_SCHEMA Index
- Transaction Isolation Level Index
- JOIN Types Index
- Operator Index
- Option Index
- Privileges Index
- SQL Modes Index
- Status Variable Index
- Statement/Syntax Index
- System Variable Index
MySQL provides privileges that apply in different contexts and at different levels of operation:
Administrative privileges enable users to manage operation of the MySQL server. These privileges are global because they are not specific to a particular database.
Database privileges apply to a database and to all objects within it. These privileges can be granted for specific databases, or globally so that they apply to all databases.
Privileges for database objects such as tables, indexes, views, and stored routines can be granted for specific objects within a database, for all objects of a given type within a database (for example, all tables in a database), or globally for all objects of a given type in all databases).
Information about account privileges is stored in the
user
,db
,host
,tables_priv
,columns_priv
, andprocs_priv
tables in themysql
database (see Section 5.4.2, “Privilege System Grant Tables”). The MySQL server reads the contents of these tables into memory when it starts and reloads them under the circumstances indicated in Section 5.4.6, “When Privilege Changes Take Effect”. Access-control decisions are based on the in-memory copies of the grant tables.Some releases of MySQL introduce changes to the structure of the grant tables to add new access privileges or features. Whenever you update to a new version of MySQL, you should update your grant tables to make sure that they have the current structure so that you can take advantage of any new capabilities. See Section 4.4.8, “mysql_upgrade — Check Tables for MySQL Upgrade”.
The following table shows the privilege names used at the SQL level in the
GRANT
andREVOKE
statements, along with the column name associated with each privilege in the grant tables and the context in which the privilege applies.Privilege Column Context CREATE
Create_priv
databases, tables, or indexes DROP
Drop_priv
databases or tables GRANT OPTION
Grant_priv
databases, tables, or stored routines REFERENCES
References_priv
databases or tables EVENT
Event_priv
databases ALTER
Alter_priv
tables DELETE
Delete_priv
tables INDEX
Index_priv
tables INSERT
Insert_priv
tables SELECT
Select_priv
tables UPDATE
Update_priv
tables CREATE TEMPORARY TABLES
Create_tmp_table_priv
tables LOCK TABLES
Lock_tables_priv
tables TRIGGER
Trigger_priv
tables CREATE VIEW
Create_view_priv
views SHOW VIEW
Show_view_priv
views ALTER ROUTINE
Alter_routine_priv
stored routines CREATE ROUTINE
Create_routine_priv
stored routines EXECUTE
Execute_priv
stored routines FILE
File_priv
file access on server host CREATE USER
Create_user_priv
server administration PROCESS
Process_priv
server administration RELOAD
Reload_priv
server administration REPLICATION CLIENT
Repl_client_priv
server administration REPLICATION SLAVE
Repl_slave_priv
server administration SHOW DATABASES
Show_db_priv
server administration SHUTDOWN
Shutdown_priv
server administration SUPER
Super_priv
server administration ALL [PRIVILEGES]
server administration USAGE
server administration The following list provides a general description of each privilege available in MySQL. Particular SQL statements might have more specific privilege requirements than indicated here. If so, the description for the statement in question provides the details.
The
ALL
orALL PRIVILEGES
privilege specifier is shorthand. It stands for “all privileges available at a given privilege level” (exceptGRANT OPTION
). For example, grantingALL
at the global or table level grants all global privileges or all table-level privileges.-
The
ALTER
privilege enables use ofALTER TABLE
to change the structure of or rename tables. (ALTER TABLE
also requires theINSERT
andCREATE
privileges.)MySQL Enterprise. In some circumstances, the
ALTER
privilege is entirely unnecessary—on slaves where there are no nonreplicated tables, for instance. The MySQL Enterprise Monitor notifies subscribers when accounts have inappropriate privileges. For more information, see http://www.mysql.com/products/enterprise/advisors.html. The
ALTER ROUTINE
privilege is needed to alter or drop stored routines (procedures and functions).The
CREATE
privilege enables creation of new databases and tables.The
CREATE ROUTINE
privilege is needed to create stored routines (procedures and functions).The
CREATE TEMPORARY TABLES
privilege enables the use of the keywordTEMPORARY
inCREATE TABLE
statements.The
CREATE USER
privilege enables use ofCREATE USER
,DROP USER
,RENAME USER
, andREVOKE ALL PRIVILEGES
.The
CREATE VIEW
privilege enables use ofCREATE VIEW
.The
DELETE
privilege enables rows to be deleted from tables in a database.The
DROP
privilege enables you to drop (remove) existing databases, tables, and views. Beginning with MySQL 5.1.10, theDROP
privilege is also required in order to use the statementALTER TABLE ... DROP PARTITION
on a partitioned table. Beginning with MySQL 5.1.16, theDROP
privilege is required forTRUNCATE TABLE
(before that,TRUNCATE TABLE
requires theDELETE
privilege). If you grant theDROP
privilege for themysql
database to a user, that user can drop the database in which the MySQL access privileges are stored.The
EVENT
privilege is required to create, alter, or drop events for the Event Scheduler. This privilege was added in MySQL 5.1.6.The
EXECUTE
privilege is required to execute stored routines (procedures and functions).The
FILE
privilege gives you permission to read and write files on the server host using theLOAD DATA INFILE
andSELECT ... INTO OUTFILE
statements and theLOAD_FILE()
function. A user who has theFILE
privilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.) TheFILE
privilege also enables the user to create new files in any directory where the MySQL server has write access. As a security measure, the server will not overwrite existing files.The
GRANT OPTION
privilege enables you to give to other users or remove from other users those privileges that you yourself possess.The
INDEX
privilege enables you to create or drop (remove) indexes.INDEX
applies to existing tables. If you have theCREATE
privilege for a table, you can include index definitions in theCREATE TABLE
statement.The
INSERT
privilege enables rows to be inserted into tables in a database.INSERT
is also required for theANALYZE TABLE
,OPTIMIZE TABLE
, andREPAIR TABLE
table-maintenance statements.The
LOCK TABLES
privilege enables the use of explicitLOCK TABLES
statements to lock tables for which you have theSELECT
privilege. This includes the use of write locks, which prevents other sessions from reading the locked table.The
PROCESS
privilege pertains to display of information about the threads executing within the server (that is, information about the statements being executed by sessions). The privilege enables use ofSHOW PROCESSLIST
or mysqladmin processlist to see threads belonging to other accounts; you can always see your own threads.The
REFERENCES
privilege currently is unused.-
The
RELOAD
privilege enables use of theFLUSH
statement. It also enables mysqladmin commands that are equivalent toFLUSH
operations:flush-hosts
,flush-logs
,flush-privileges
,flush-status
,flush-tables
,flush-threads
,refresh
, andreload
.The
reload
command tells the server to reload the grant tables into memory.flush-privileges
is a synonym forreload
. Therefresh
command closes and reopens the log files and flushes all tables. The otherflush-
commands perform functions similar toxxx
refresh
, but are more specific and may be preferable in some instances. For example, if you want to flush just the log files,flush-logs
is a better choice thanrefresh
. The
REPLICATION CLIENT
privilege enables the use ofSHOW MASTER STATUS
andSHOW SLAVE STATUS
.The
REPLICATION SLAVE
privilege should be granted to accounts that are used by slave servers to connect to the current server as their master. Without this privilege, the slave cannot request updates that have been made to databases on the master server.-
The
SELECT
privilege enables you to select rows from tables in a database.SELECT
statements require theSELECT
privilege only if they actually retrieve rows from a table. SomeSELECT
statements do not access tables and can be executed without permission for any database. For example, you can useSELECT
as a simple calculator to evaluate expressions that make no reference to tables:SELECT 1+1; SELECT PI()*2;
The
SELECT
privilege is also needed for other statements that read column values. For example,SELECT
is needed for columns referenced on the right hand side ofcol_name
=expr
assignment inUPDATE
statements or for columns named in theWHERE
clause ofDELETE
orUPDATE
statements. -
The
SHOW DATABASES
privilege enables the account to see database names by issuing theSHOW DATABASE
statement. Accounts that do not have this privilege see only databases for which they have some privileges, and cannot use the statement at all if the server was started with the--skip-show-database
option. Note that any global privilege is a privilege for the database.MySQL Enterprise. The
SHOW DATABASES
privilege should be granted only to users who need to see all the databases on a MySQL server. Subscribers to the MySQL Enterprise Monitor are alerted when servers are started without the--skip-show-database
option. For more information, see http://www.mysql.com/products/enterprise/advisors.html. The
SHOW VIEW
privilege enables use ofSHOW CREATE VIEW
.The
SHUTDOWN
privilege enables use of the mysqladmin shutdown command. There is no corresponding SQL statement.-
The
SUPER
privilege enables an account to useCHANGE MASTER TO
,KILL
or mysqladmin kill to kill threads belonging to other accounts (you can always kill your own threads),PURGE BINARY LOGS
, configuration changes viaSET GLOBAL
to modify global system variables, the mysqladmin debug command, enabling or disabling logging, performing updates even if theread_only
system variable is enabled, starting and stopping replication on slave servers, specification of any account in theDEFINER
attribute of stored programs and views, and allows you to connect (once) even if the connection limit controlled by themax_connections
system variable is reached.To create or alter stored functions if binary logging is enabled, you may also need the
SUPER
privilege, as described in Section 19.7, “Binary Logging of Stored Programs”. The
TRIGGER
privilege enables you to create and drop triggers. You must have this privilege for a table to create or drop triggers for that table. This privilege was added in MySQL 5.1.6. (Prior to MySQL 5.1.6, trigger operations required theSUPER
privilege.)The
UPDATE
privilege enables rows to be updated in tables in a database.The
USAGE
privilege specifier stands for “no privileges.” It is used at the global level withGRANT
to modify account attributes such as resource limits or SSL characteristics without affecting existing account privileges.
It is a good idea to grant to an account only those privileges that it needs. You should exercise particular caution in granting the
FILE
and administrative privileges:The
FILE
privilege can be abused to read into a database table any files that the MySQL server can read on the server host. This includes all world-readable files and files in the server's data directory. The table can then be accessed usingSELECT
to transfer its contents to the client host.The
GRANT OPTION
privilege enables users to give their privileges to other users. Two users that have different privileges and with theGRANT OPTION
privilege are able to combine privileges.The
ALTER
privilege may be used to subvert the privilege system by renaming tables.The
SHUTDOWN
privilege can be abused to deny service to other users entirely by terminating the server.The
PROCESS
privilege can be used to view the plain text of currently executing statements, including statements that set or change passwords.The
SUPER
privilege can be used to terminate other sessions or change how the server operates.-
Privileges granted for the
mysql
database itself can be used to change passwords and other access privilege information. Passwords are stored encrypted, so a malicious user cannot simply read them to know the plain text password. However, a user with write access to theuser
tablePassword
column can change an account's password, and then connect to the MySQL server using that account.MySQL Enterprise. Accounts with unnecessary global privileges constitute a security risk. Subscribers to the MySQL Enterprise Monitor are automatically alerted to the existence of such accounts. For detailed information, see http://www.mysql.com/products/enterprise/advisors.html.