{"id":8815,"date":"2019-09-14T02:44:03","date_gmt":"2019-09-14T09:44:03","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=8815"},"modified":"2023-11-13T18:29:34","modified_gmt":"2023-11-14T01:29:34","slug":"mysql-show-grants","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/","title":{"rendered":"MySQL SHOW GRANTS"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you will learn how to use MySQL <code>SHOW GRANTS<\/code> statement to view the privileges previously granted to a user or role.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL SHOW GRANTS statement<\/h2>\n\n\n\n<p>The MySQL <code>SHOW GRANTS<\/code> statement returns all privileges and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-roles\/\">roles<\/a> granted to an account user or role.<\/p>\n\n\n\n<p>Here&#8217;s the basic syntax of the <code>SHOW GRANTS<\/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\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span>\n&#91;<span class=\"hljs-keyword\">FOR<\/span> {<span class=\"hljs-keyword\">user<\/span> | <span class=\"hljs-keyword\">role<\/span>}\n&#91;<span class=\"hljs-keyword\">USING<\/span> <span class=\"hljs-keyword\">role<\/span> &#91;, <span class=\"hljs-keyword\">role<\/span>] ...]]<\/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 the name of the user account or role for which you want to display the previously granted privileges after the <code>FOR<\/code> keyword. If you omit the <code>FOR<\/code> clause, the <code>SHOW GRANTS<\/code> statement returns the privileges of the current user.<\/li>\n\n\n\n<li>Second, use the <code>USING<\/code> clause to inspect the privileges associated with roles for the user. The roles specified in the <code>USING<\/code> clause must have been previously granted to the user.<\/li>\n<\/ul>\n\n\n\n<p class=\"note\">To execute the <code>SHOW GRANTS<\/code> statement, you need to have <code>SELECT<\/code> privilege for the <code>mysql<\/code> system database, except when you show privileges and roles for the current user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL SHOW GRANTS statement examples<\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the MySQL <code>SHOW GRANTS<\/code> statement.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Using the SHOW GRANTS statement to display the privileges of the current user<\/h3>\n\n\n\n<p>The following statement uses the <code>SHOW GRANTS<\/code> statement to display the privileges granted to the current user:<\/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\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span>;<\/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>If you use the mysql tool, the output may not be readable. To fix it, you can display the output in the vertical layout:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SHOW GRANTS\\G<\/code><\/span><\/pre>\n\n\n<p>It is equivalent to the following statement:<\/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\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span> <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">CURRENT_USER<\/span>\\G<\/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>and<\/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\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span> <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">CURRENT_USER<\/span>()\\G<\/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>Note that both <code>CURRENT_USER<\/code> and <code>CURRENT_USER()<\/code> functions return the currently logged-in user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Using the SHOW GRANTS statement to display the privileges granted to a user<\/h3>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-database\/\">create a new database<\/a> named <code>vehicles<\/code>:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> vehicles;<\/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>Second, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-select-database\/\">select the database<\/a> <code>vehicles<\/code> :<\/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\">USE<\/span> vehicles;<\/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>Third, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\">create a new table<\/a> called <code>cars<\/code> in the <code>vehicles<\/code> database:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> cars (\n    <span class=\"hljs-keyword\">id<\/span> <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT,\n    make <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    <span class=\"hljs-keyword\">model<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    PRIMARY <span class=\"hljs-keyword\">KEY<\/span> (<span class=\"hljs-keyword\">id<\/span>)\n);<\/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>Fourth, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-create-user\/\">create a new user<\/a> called <code>musk@localhost<\/code>:<\/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> musk@localhost \n<span class=\"hljs-keyword\">IDENTIFIED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'Super1Pass!'<\/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>Fifth, show the default privileges granted to the user <code>musk@localhost<\/code>:<\/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> \n<span class=\"hljs-keyword\">FOR<\/span> musk@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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"40\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png\" alt=\"show grants\" class=\"wp-image-8820\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png 278w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-200x29.png 200w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/figure>\n\n\n\n<p>The <code>GRANT USAGE<\/code> is the synonym for no privilege. By default, when a new user is created, it has no privilege.<\/p>\n\n\n\n<p>Sixth, grant all privileges on the <code>vehicles<\/code> database to the user <code>musk@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" 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> vehicles.* \n<span class=\"hljs-keyword\">TO<\/span> musk@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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>Finally, show the privileges granted to the user <code>musk@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\">SHOW<\/span> <span class=\"hljs-keyword\">GRANTS<\/span> \n<span class=\"hljs-keyword\">FOR<\/span> musk@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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"58\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-example.png\" alt=\"show grants for a user example\" class=\"wp-image-8819\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-example.png 347w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-example-200x33.png 200w\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3) Using the SHOW GRANTS statement to display the privileges granted for a role<\/h3>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-roles\/\">create a new role<\/a> called <code>writer@localhost<\/code>:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">ROLE<\/span> writer@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>Second, show privileges granted for the role <code>writer@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" 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> \n<span class=\"hljs-keyword\">FOR<\/span> writer@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"325\" height=\"37\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role.png\" alt=\"show grants for a role\" class=\"wp-image-8821\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role.png 325w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role-200x23.png 200w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/figure>\n\n\n\n<p>Third, grant <code>SELECT<\/code>, <code>INSERT<\/code>, <code>UPDATE<\/code>, and <code>DELETE<\/code> privileges on the <code>vehicles<\/code> database to the <code>writer@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" 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>, \n    <span class=\"hljs-keyword\">INSERT<\/span>, \n    <span class=\"hljs-keyword\">UPDATE<\/span>, \n    <span class=\"hljs-keyword\">DELETE<\/span>\n<span class=\"hljs-keyword\">ON<\/span> vehicles.*\n<span class=\"hljs-keyword\">TO<\/span> writer@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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, show privileges granted for the role <code>writer@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" 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> \n<span class=\"hljs-keyword\">FOR<\/span> writer@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"453\" height=\"55\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role-example.png\" alt=\"show grants for a role example\" class=\"wp-image-8818\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role-example.png 453w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-role-example-200x24.png 200w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4) Using SHOW GRANTS with USING clause example<\/h3>\n\n\n\n<p>First, create a new account user called <code>jame@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" 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> jame@localhost\n<span class=\"hljs-keyword\">IDENTIFIED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'Secret@Pass1'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><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, grant the <code>EXECUTE<\/code> privilege to the user <code>jame@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" 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> vehicles.* \n<span class=\"hljs-keyword\">TO<\/span> jame@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><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>Third, grant the role <code>writer@localhost<\/code> to the user <code>jame@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" 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> writer@localhost\n<span class=\"hljs-keyword\">TO<\/span> jame@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><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, display the privileges granted to the user <code>jame@localhost<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" 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> \n<span class=\"hljs-keyword\">FOR<\/span> jame@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"382\" height=\"84\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-privileges-and-roles.png\" alt=\"\" class=\"wp-image-8817\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-privileges-and-roles.png 382w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-privileges-and-roles-200x44.png 200w\" sizes=\"auto, (max-width: 382px) 100vw, 382px\" \/><\/figure>\n\n\n\n<p>Finally, use the <code>USING<\/code> clause in the <code>SHOW GRANTS<\/code> statement to display privileges associated with the <code>writer@localhost<\/code> role:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" 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> \n<span class=\"hljs-keyword\">FOR<\/span> jame@localhost \n<span class=\"hljs-keyword\">USING<\/span> writer@localhost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"99\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-using-clause.png\" alt=\"show grants for a user with using clause\" class=\"wp-image-8816\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-using-clause.png 450w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants-for-a-user-with-using-clause-200x44.png 200w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/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>SHOW GRANTS<\/code> statement to display privileges granted to a user or role.<\/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=\"8815\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/\"\n\t\t\t\tdata-post-title=\"MySQL SHOW GRANTS\"\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=\"8815\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/\"\n\t\t\t\tdata-post-title=\"MySQL SHOW GRANTS\"\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 SHOW GRANTS statement to display the privileges and roles assigned to an account user.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":441,"menu_order":34,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-8815","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL SHOW GRANTS<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.\" \/>\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-show-grants\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL SHOW GRANTS\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-14T01:29:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 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-show-grants\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/\",\"name\":\"MySQL SHOW GRANTS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/show-grants.png\",\"datePublished\":\"2019-09-14T09:44:03+00:00\",\"dateModified\":\"2023-11-14T01:29:34+00:00\",\"description\":\"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/show-grants.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2019\\\/09\\\/show-grants.png\",\"width\":278,\"height\":40,\"caption\":\"show grants\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-administration\\\/mysql-show-grants\\\/#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 SHOW GRANTS\"}]},{\"@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 SHOW GRANTS","description":"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.","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-show-grants\/","og_locale":"en_US","og_type":"article","og_title":"MySQL SHOW GRANTS","og_description":"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-11-14T01:29:34+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/","url":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/","name":"MySQL SHOW GRANTS","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png","datePublished":"2019-09-14T09:44:03+00:00","dateModified":"2023-11-14T01:29:34+00:00","description":"In this tutorial, you will learn how to use the MySQL SHOW GRANTS statement to display the privileges and roles assigned to an account user.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/show-grants.png","width":278,"height":40,"caption":"show grants"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-show-grants\/#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 SHOW GRANTS"}]},{"@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\/8815","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=8815"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/8815\/revisions"}],"predecessor-version":[{"id":12398,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/8815\/revisions\/12398"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/441"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=8815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}