{"id":32713,"date":"2023-02-07T03:20:44","date_gmt":"2023-02-07T03:20:44","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=32713"},"modified":"2023-02-07T03:20:46","modified_gmt":"2023-02-07T03:20:46","slug":"mysql-tutorials-how-to-grant-user-access-to-database","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/mysql-tutorials-how-to-grant-user-access-to-database\/","title":{"rendered":"MySql Tutorials: How to grant user access to Database?"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>To grant a user access to a specific database in MySQL, you can use the following GRANT statement:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">GRANT privileges ON database_name.* TO <span class=\"hljs-string\">'user_name'<\/span>@<span class=\"hljs-string\">'host'<\/span> &#91;IDENTIFIED BY <span class=\"hljs-string\">'password'<\/span>];\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>privileges<\/code>: the privileges you want to grant to the user. This can be a combination of SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, and other privileges.<\/li>\n\n\n\n<li><code>database_name<\/code>: the name of the database you want to grant the user access to.<\/li>\n\n\n\n<li><code>user_name<\/code>: the name of the user you want to grant the privileges to.<\/li>\n\n\n\n<li><code>host<\/code>: the host from which the user is connecting. This can be specified as a wildcard (e.g., <code>'%'<\/code>) to allow access from any host.<\/li>\n\n\n\n<li><code>password<\/code>: the password for the user (optional).<\/li>\n<\/ul>\n\n\n\n<p>For example, to grant a user with the username <code>'john'<\/code> and password <code>'password'<\/code> the ability to select data from the database <code>'mydatabase'<\/code>, the following command can be used:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">GRANT SELECT ON mydatabase.* TO <span class=\"hljs-string\">'john'<\/span>@<span class=\"hljs-string\">'%'<\/span> IDENTIFIED BY <span class=\"hljs-string\">'password'<\/span>;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>After executing the GRANT statement, you need to run the <code>FLUSH PRIVILEGES<\/code> command to reload the privileges and apply the changes:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">FLUSH PRIVILEGES;\r\n<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>To grant a user access to a specific database in MySQL, you can use the following GRANT statement: Where: For example, to grant a user with the username &#8216;john&#8217; and password &#8216;password&#8217; the ability to select data from the database &#8216;mydatabase&#8217;, the following command can be used: After executing the GRANT statement, you need to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-32713","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=32713"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32713\/revisions"}],"predecessor-version":[{"id":32714,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32713\/revisions\/32714"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=32713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=32713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=32713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}