{"id":31771,"date":"2018-10-31T12:51:51","date_gmt":"2018-10-31T07:21:51","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=31771"},"modified":"2018-10-31T12:53:56","modified_gmt":"2018-10-31T07:23:56","slug":"grant-permissions-to-mysql-user-on-linux-command","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/grant-permissions-to-mysql-user-on-linux-command\/","title":{"rendered":"Grant Permissions to a MySQL User on Linux via Command Line"},"content":{"rendered":"<h3 id=\"pre-flight-check\"><span style=\"color: #800000;\"><strong>Pre-Flight Check<\/strong><\/span><\/h3>\n<p>These directions square measure meant for granting a MySQL user permissions on LINUX system via the instruction<\/p>\n<p>I\u2019ll be engaging from a <strong>Liquid internet Core<\/strong> Managed <strong>CentOS six.5<\/strong> server, and I\u2019ll be logged in as root.<\/p>\n<h3 id=\"login-to-mysql\"><span style=\"color: #333399;\">Login to MySQL<\/span><\/h3>\n<p>First we\u2019ll login to the MySQL server from the instruction with the following command:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">mysql -u root -p<\/code><\/pre> <\/div>\n<p>In this case, I\u2019ve mere the user root with the <strong>-u flag<\/strong>, so used the<strong> -p flag<\/strong> so MySQL prompts for a parole. Enter your current parole to finish the login.<\/p>\n<p>If you would like to alter your root (or any other) parole within the info, then follow this tutorial on ever-changing a parole for MySQL via the <a href=\"https:\/\/www.wikitechy.com\/technology\/force-a-delete\/\" target=\"_blank\" rel=\"noopener\">command<\/a><\/p>\n<p>You should currently be at a MySQL prompt that appears terribly almost like this:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">mysql&gt;<\/code><\/pre> <\/div>\n<p>If you haven\u2019t nonetheless created a MySQL user, please visit our tutorial on making a <a href=\"https:\/\/www.wikitechy.com\/technology\/create-mysql-user-on-linux-command-line\/\" target=\"_blank\" rel=\"noopener\">MySQL user<\/a>.<\/p>\n<h3 id=\"grant-permissions-to-mysql-user\"><span style=\"color: #003366;\">Grant Permissions to MySQL User:<\/span><\/h3>\n<p>The basic syntax for granting permissions is as follows:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">GRANT permission ON database.table TO &#039;user&#039;@&#039;localhost&#039;;<\/code><\/pre> <\/div>\n<p><span style=\"color: #3366ff;\"><strong>Here is a brief list of usually used permissions :<\/strong><\/span><\/p>\n<p><span style=\"color: #008080;\"><strong>ALL<\/strong> <\/span>\u2013 enable complete access to a particular info. If a info isn&#8217;t such, then enable complete access to the whole lot of MySQL.<\/p>\n<p><span style=\"color: #008080;\"><strong>CREATE<\/strong> <\/span>\u2013 enable a user to make databases and tables.<\/p>\n<p><span style=\"color: #008080;\"><strong>DELETE <\/strong><\/span>\u2013 enable a user to delete rows from a table.<\/p>\n<p><span style=\"color: #008080;\"><strong>DROP<\/strong> <\/span>\u2013 enable a user to drop databases and tables.<\/p>\n<p><span style=\"color: #008080;\"><strong>EXECUTE<\/strong><\/span> \u2013 enable a user to execute hold on routines.<\/p>\n<p><span style=\"color: #008080;\"><strong>GRANT <\/strong><\/span>possibility \u2013 enable a user to grant or take away another user\u2019s privileges.<\/p>\n<p><span style=\"color: #008080;\"><strong>INSERT<\/strong><\/span> \u2013 enable a user to insert rows from a table.<\/p>\n<p><span style=\"color: #008080;\"><strong>SELECT<\/strong> <\/span>\u2013 enable a user to pick knowledge from a info.<\/p>\n<p><span style=\"color: #008080;\"><strong>SHOW DATABASES<\/strong><\/span>&#8211; enable a user to look at an inventory of all databases.<\/p>\n<p><span style=\"color: #008080;\"><strong>UPDATE <\/strong><\/span>\u2013 enable a user to update rows in a table.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #333300;\"><strong>Example #1:<\/strong><\/span> To grant produce permissions for all databases * and every one tables * to the user we created within the previous tutorial, testuser , use the following command:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">GRANT CREATE ON *.* TO &#039;testuser&#039;@&#039;localhost&#039;;<\/code><\/pre> <\/div>\n<p>Using an asterisk (*) within the place of the information or table is a very valid possibility, and implies all <a href=\"https:\/\/www.wikitechy.com\/tutorials\/laravel\/laravel-database\" target=\"_blank\" rel=\"noopener\">databases<\/a> or all tables.<\/p>\n<p><span style=\"color: #333300;\"><strong>Example #2<\/strong>:<\/span> To grant testuser the flexibility to <a href=\"https:\/\/www.wikitechy.com\/tutorials\/sql\/drop-table\" target=\"_blank\" rel=\"noopener\">drop tables<\/a> within the specific information, tutorial_database , use the DROP permission:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">GRANT DROP ON tutorial_database.* TO &#039;testuser&#039;@&#039;localhost&#039;;<\/code><\/pre> <\/div>\n<p>When finished making your permission changes, it\u2019s good practice to reload all the privileges with the flush command!<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">FLUSH PRIVILEGES;<\/code><\/pre> <\/div>\n<h3 id=\"view-grants-for-mysql-user\"><span style=\"color: #003300;\">View Grants for MySQL User:<\/span><\/h3>\n<p>After you\u2019ve granted permissions to a MySQL user you\u2019ll probably want to double check them. Use the following command to check the grants for testuser:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SHOW GRANTS FOR &#039;testuser&#039;@&#039;localhost&#039;;<\/code><\/pre> <\/div>\n<h3 id=\"output\"><span style=\"color: #008000;\">Output:<\/span><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-less code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-less code-embed-code\">+---------------------------------------------------------------------+<br\/>| Grants for testuser@localhost                                           |<br\/>+---------------------------------------------------------------------+<br\/>| GRANT ALL PRIVILEGES ON *.* TO &#039;testuser&#039;@&#039;localhost&#039; WITH GRANT OPTION |<br\/>+---------------------------------------------------------------------+<\/code><\/pre> <\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pre-Flight Check These directions square measure meant for granting a MySQL user permissions on LINUX system via the instruction I\u2019ll be engaging from a Liquid internet Core Managed CentOS six.5 server, and I\u2019ll be logged in as root. Login to MySQL First we\u2019ll login to the MySQL server from the instruction with the following command: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699,27],"tags":[85600,85597,85694,85609,85602,85608,85695,85606,85696,85598,85697,85698,85699,85700,85701,85702,534,85607,85703,85704,535,85705,85706,537],"class_list":["post-31771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-mysql","tag-create-user-mysql","tag-mysql-create-remote-user","tag-mysql-create-user","tag-mysql-grant-all-privileges-identified-by-password","tag-mysql-grant-all-privileges-to-root","tag-mysql-grant-all-privileges-to-user-from-any-host","tag-mysql-grant-super","tag-mysql-grant-usage","tag-mysql-grant-usage-identified-by-password","tag-mysql-grant-user-access-to-database","tag-mysql-grants","tag-mysql-privileges","tag-mysql-privileges-list","tag-mysql-remove-grants","tag-mysql-revoke-privileges","tag-mysql-show-all-users","tag-mysql-show-current-user","tag-mysql-show-grants","tag-mysql-show-grants-on-table","tag-mysql-show-grants-wildcard","tag-mysql-show-user-password","tag-mysql-show-users-permissions","tag-mysql-with-grant-option","tag-mysql-user-table"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/31771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=31771"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/31771\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/1205"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=31771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=31771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=31771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}