{"id":449,"date":"2011-04-28T12:14:28","date_gmt":"2011-04-28T12:14:28","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=449"},"modified":"2023-12-29T05:22:23","modified_gmt":"2023-12-29T12:22:23","slug":"mysql-grant","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/","title":{"rendered":"MySQL GRANT"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the MySQL <code>GRANT<\/code> statement to assign privileges to user accounts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the MySQL GRANT statement<\/h2>\n\n\n\n<p>The <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-create-user\/\">CREATE USER<\/a><\/code> statement creates a user account with no privileges. It means that the user account can log in to the MySQL Server, but cannot do anything such as <a href=\"https:\/\/www.mysqltutorial.org\/mysql-select-database\/\">selecting a database<\/a> and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select\/\">querying data<\/a> from tables.<\/p>\n\n\n\n<p>To enable the user account to work with database objects, you need to grant it privileges. You use the <code>GRANT<\/code> statement to assign one or more privileges to the user account. <\/p>\n\n\n\n<p>Here&#8217;s the basic syntax of the <code>GRANT<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> privilege &#91;,privilege],.. \n<span class=\"hljs-keyword\">ON<\/span> privilege_level \n<span class=\"hljs-keyword\">TO<\/span> account_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, specify one or more privileges after the <code>GRANT<\/code> keyword. If you grant multiple privileges, you need to separate privileges by commas.<\/li>\n\n\n\n<li>Second, specify the <code>privilege_level<\/code>, which determines the extent to which the privileges apply. More information on privilege levels will be provided shortly.<\/li>\n\n\n\n<li>Third, specify the account name of the user you want to grant privileges after the <code>TO<\/code> keyword.<\/li>\n<\/ul>\n\n\n\n<p class=\"note\">Notice that to use the <code>GRANT<\/code> statement, you must have the <code class=\"literal\">GRANT OPTION<\/code> privilege and the privileges that you are granting. If the system variable <code class=\"literal\">read_only<\/code> is enabled, you need to have\u00a0the <code class=\"literal\">SUPER<\/code> privilege to execute the <code>GRANT<\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL privilege levels<\/h2>\n\n\n\n<p>MySQL supports the following privilege levels:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"138\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/MySQL-Grant-Privilege-Level.png\" alt=\"MySQL Grant - Privilege Levels\" class=\"wp-image-8801\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/MySQL-Grant-Privilege-Level.png 728w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/MySQL-Grant-Privilege-Level-200x38.png 200w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Global Privileges<\/h3>\n\n\n\n<p><strong>Global privileges<\/strong> apply to all databases in a MySQL Server. To assign all global privileges, you use the <code>*.*<\/code> syntax, for example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">SELECT<\/span> \n<span class=\"hljs-keyword\">ON<\/span> *.* \n<span class=\"hljs-keyword\">TO<\/span> bob@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The account user <code>bob@localhost<\/code> can manage all databases of the current MySQL Server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Database privileges<\/h3>\n\n\n\n<p><strong>Database privileges<\/strong> apply to all objects in a particular database. To assign database-level privileges, you use the <code>ON database_name.*<\/code> syntax, for example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">INSERT<\/span> \n<span class=\"hljs-keyword\">ON<\/span> classicmodels.* \n<span class=\"hljs-keyword\">TO<\/span> bob@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>bob@localhost<\/code> can manage all objects in the <code>classicmodels<\/code> database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Table privileges<\/h3>\n\n\n\n<p><strong>Table privileges<\/strong> apply to all columns in a table. To assign table-level privileges, you use the <code>ON database_name.table_name<\/code> syntax. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">DELETE<\/span> \n<span class=\"hljs-keyword\">ON<\/span> classicmodels.employees \n<span class=\"hljs-keyword\">TO<\/span> bob@localhsot;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>bob@localhost<\/code> can manage rows from the <code>employees<\/code> table in the <code>classicmodels<\/code> database.<\/p>\n\n\n\n<p>If you skip the database name, MySQL uses the default database or issues an error if there is no default database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Column privileges<\/h3>\n\n\n\n<p><strong>Column privileges<\/strong> apply to individual columns within a table. You must specify the column or columns for each privilege. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> \n   <span class=\"hljs-keyword\">SELECT<\/span> (employeeNumner,lastName, firstName,email), \n   <span class=\"hljs-keyword\">UPDATE<\/span>(lastName) \n<span class=\"hljs-keyword\">ON<\/span> employees \n<span class=\"hljs-keyword\">TO<\/span> bob@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>bob@localhost<\/code> can select data from four columns: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>employeeNumber<\/code> <\/li>\n\n\n\n<li><code>lastName<\/code> <\/li>\n\n\n\n<li><code>firstName<\/code><\/li>\n\n\n\n<li><code>email<\/code><\/li>\n<\/ul>\n\n\n\n<p>And updates only the <code>lastName<\/code> column in the <code>employees<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Stored routine privileges<\/h3>\n\n\n\n<p><strong>Stored routine privileges<\/strong> apply to stored procedures and stored functions. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">EXECUTE<\/span> \n<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">PROCEDURE<\/span> CheckCredit \n<span class=\"hljs-keyword\">TO<\/span> bob@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>bob@localhost<\/code> can execute the stored procedure <code>CheckCredit<\/code> in the current database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Proxy user privileges<\/h3>\n\n\n\n<p><strong>Proxy user privileges<\/strong> allow one user to be a proxy for another. The proxy user gets all the privileges of the proxied user. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> PROXY \n<span class=\"hljs-keyword\">ON<\/span> root \n<span class=\"hljs-keyword\">TO<\/span> alice@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, <code>alice@localhost<\/code> assumes all privileges of the user <code>root<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL GRANT statement examples<\/h2>\n\n\n\n<p>Typically, you use the <code>CREATE USER<\/code> statement to create a new user account first and then use the <code>GRANT<\/code> statement to grant privileges to the user.<\/p>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-create-user\/\">create a new user<\/a> named <code>super@localhost<\/code> by using the following\u00a0<code>CREATE USER<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">USER<\/span> super@localhost \n<span class=\"hljs-keyword\">IDENTIFIED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'Secure1Pass!'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, show the privileges assigned to <code>super@localhost<\/code> user by using the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/\">SHOW GRANTS<\/a><\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span> <span class=\"hljs-keyword\">FOR<\/span> super@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+-------------------------------------------+\r\n| Grants <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-keyword\">super<\/span>@localhost                |\r\n+-------------------------------------------+\r\n| GRANT USAGE ON *.* TO <span class=\"hljs-string\">`super`<\/span>@<span class=\"hljs-string\">`localhost`<\/span> |\r\n+-------------------------------------------+\r\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>USAGE<\/code> means that the <code>super@localhost<\/code> can log in to the database but has no privilege.<\/p>\n\n\n\n<p>Third, grant all privileges in all databases in the current database server to <code>super@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">ALL<\/span> \n<span class=\"hljs-keyword\">ON<\/span> classicmodels.* \n<span class=\"hljs-keyword\">TO<\/span> super@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, use the <code>SHOW GRANTS<\/code> statement again:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span> <span class=\"hljs-keyword\">FOR<\/span> super@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+------------------------------------------------------------------+\r\n| Grants <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-keyword\">super<\/span>@localhost                                       |\r\n+------------------------------------------------------------------+\r\n| GRANT USAGE ON *.* TO <span class=\"hljs-string\">`super`<\/span>@<span class=\"hljs-string\">`localhost`<\/span>                        |\r\n| GRANT ALL PRIVILEGES ON <span class=\"hljs-string\">`classicmodels`<\/span>.* TO <span class=\"hljs-string\">`super`<\/span>@<span class=\"hljs-string\">`localhost`<\/span> |\r\n+------------------------------------------------------------------+\r\n<span class=\"hljs-number\">2<\/span> rows <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Permissible privileges for the GRANT statement<\/h2>\n\n\n\n<p>The following table illustrates all permissible privileges that you can use for the <code>GRANT<\/code> and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-revoke\/\"><code>REVOKE<\/code><\/a> statement:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Privilege<\/strong><\/td><td><strong>Meaning<\/strong><\/td><td><strong>Level<\/strong><\/td><\/tr><tr><td><strong>Global<\/strong><\/td><td><strong>Database<\/strong><\/td><td><strong>Table<\/strong><\/td><td><strong>Column<\/strong><\/td><td><strong>Stored Routine<\/strong><\/td><td><strong>Proxy<\/strong><\/td><\/tr><tr><td>ALL [PRIVILEGES]<\/td><td>Allow the user to alter and drop stored procedures or stored functions.<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>ALTER<\/td><td>Allow the user to use the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-alter-table\/\">ALTER TABLE<\/a><\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>ALTER ROUTINE<\/td><td>Allow the user to create databases and tables<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td>X<\/td><td><\/td><\/tr><tr><td>CREATE<\/td><td>Allow the user to create stored procedures and stored functions<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>CREATE ROUTINE<\/td><td>Allow the user to create a temporary table by using <code>CREATE TEMPORARY TABLE<\/code> statement<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>CREATE TABLESPACE<\/td><td>Allow the user to create, alter, or drop tablespaces and log file groups<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>CREATE TEMPORARY TABLES<\/td><td>Allow the user to use the <code>CREATE USER, DROP USER, RENAME USER<\/code>, and <code>REVOKE ALL PRIVILEGES<\/code> statements.<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>CREATE USER<\/td><td>Allow the user to create or modify the view.<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>CREATE VIEW<\/td><td>Allow the user to use <code>DELETE<\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>DELETE<\/td><td>Allow the user to execute stored routines<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>DROP<\/td><td>Allow the user to drop database, table, and view<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>EVENT<\/td><td>Allow the user to use events for the Event Scheduler.<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>EXECUTE<\/td><td>Allow the user to drop the database, table, and view<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>FILE<\/td><td>Allow the user to have privileges to grant or revoke privileges from other accounts.<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>GRANT OPTION<\/td><td>Allow the user to create or drop indexes.<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td>X<\/td><td>X<\/td><\/tr><tr><td>INDEX<\/td><td>Allow the user to create or drop indexes.<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>INSERT<\/td><td>Allow the user to use the <code>INSERT<\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><\/tr><tr><td>LOCK TABLES<\/td><td>Allow the user to query to see where the master or slave servers are<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>PROCESS<\/td><td>Allow the user to see all processes with <code>SHOW PROCESSLIST<\/code> statement.<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>PROXY<\/td><td>Enable user proxying.<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>REFERENCES<\/td><td>Allow user to create a foreign key<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><\/tr><tr><td>RELOAD<\/td><td>Allow the user to use <code>FLUSH<\/code> statement<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>REPLICATION CLIENT<\/td><td>Allow the user to query to see where master or slave servers are<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>REPLICATION SLAVE<\/td><td>Allow the user to use replicate slaves to read binary log events from the master.<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>SELECT<\/td><td>Allow the user to use <code>SELECT<\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><\/tr><tr><td>SHOW DATABASES<\/td><td>Allow user to show all databases<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>SHOW VIEW<\/td><td>Allow the user to use <code>SHOW CREATE VIEW<\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>SHUTDOWN<\/td><td>Allow user to use mysqladmin shutdown command<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>SUPER<\/td><td>Allow the user to use other administrative operations such as <code>CHANGE MASTER TO<\/code>, <code>KILL<\/code>, <code>PURGE BINARY LOGS<\/code>, <code>SET GLOBAL<\/code>, and mysqladmin command<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>TRIGGER<\/td><td>Allow the user to use <code>TRIGGER<\/code> operations.<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><td><\/td><\/tr><tr><td>UPDATE<\/td><td>Allow the user to use the <code>UPDATE<\/code> statement<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td>X<\/td><td><\/td><td><\/td><\/tr><tr><td>USAGE<\/td><td>Equivalent to &#8220;no privileges&#8221;<\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the MySQL <code>GRANT<\/code> statement to grant privileges to a user.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"449\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/\"\n\t\t\t\tdata-post-title=\"MySQL GRANT\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"449\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/\"\n\t\t\t\tdata-post-title=\"MySQL GRANT\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.<\/p>\n","protected":false},"author":2,"featured_media":5414,"parent":441,"menu_order":31,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-449","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL GRANT<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL GRANT\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-29T12:22:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/04\/MySQL-GRANT-Statement.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"112\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/\",\"name\":\"MySQL GRANT\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/04\\\/MySQL-GRANT-Statement.jpg\",\"datePublished\":\"2011-04-28T12:14:28+00:00\",\"dateModified\":\"2023-12-29T12:22:23+00:00\",\"description\":\"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/04\\\/MySQL-GRANT-Statement.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2011\\\/04\\\/MySQL-GRANT-Statement.jpg\",\"width\":150,\"height\":112},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-grant\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Administration\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL GRANT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL GRANT","description":"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/","og_locale":"en_US","og_type":"article","og_title":"MySQL GRANT","og_description":"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-29T12:22:23+00:00","og_image":[{"width":150,"height":112,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/04\/MySQL-GRANT-Statement.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/","url":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/","name":"MySQL GRANT","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/04\/MySQL-GRANT-Statement.jpg","datePublished":"2011-04-28T12:14:28+00:00","dateModified":"2023-12-29T12:22:23+00:00","description":"In this tutorial, you will learn how to use the MySQL GRANT statement to assign privileges to a user account.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/04\/MySQL-GRANT-Statement.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2011\/04\/MySQL-GRANT-Statement.jpg","width":150,"height":112},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-grant\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Administration","item":"https:\/\/www.mysqltutorial.org\/mysql-administration\/"},{"@type":"ListItem","position":3,"name":"MySQL GRANT"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/449\/revisions"}],"predecessor-version":[{"id":12391,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/449\/revisions\/12391"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/5414"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}