{"id":229,"date":"2025-04-01T14:38:56","date_gmt":"2025-04-01T14:38:56","guid":{"rendered":"https:\/\/www.kwwd.co.uk\/blog\/?p=229"},"modified":"2025-04-01T14:38:56","modified_gmt":"2025-04-01T14:38:56","slug":"mysql-check-user-exists-grant-privileges-on-database","status":"publish","type":"post","link":"https:\/\/www.kwwd.co.uk\/blog\/mysql-check-user-exists-grant-privileges-on-database\/","title":{"rendered":"MYSQL: Check User Exists &#038; Grant Privileges On Database"},"content":{"rendered":"<p>Check if the User Exists<\/p>\n<pre><code class=\"language-sql\">SELECT user, host FROM mysql.user WHERE user = 'your_username';<\/code><\/pre>\n<p>If the user doesn&#8217;t exist, create them first:<\/p>\n<pre><code class=\"language-sql\">CREATE USER 'your_username'@'%' IDENTIFIED BY 'your_password';<\/code><\/pre>\n<p>Grant Privileges Before Revoking<\/p>\n<pre><code class=\"language-sql\">GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'%';\r\nFLUSH PRIVILEGES;<\/code><\/pre>\n<p>Then, if needed, revoke specific privileges:<\/p>\n<pre><code class=\"language-sql\">REVOKE CREATE, DROP, GRANT OPTION, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON your_database.* FROM 'your_username'@'%';<\/code><\/pre>\n<p>If the user is created with &#8216;your_username&#8217;@&#8217;localhost&#8217;, but you are applying @&#8217;%&#8217;, adjust your queries:<\/p>\n<pre><code class=\"language-sql\">GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost';<\/code><\/pre>\n<p>If nothing else works, deleting and recreating the user may help:<\/p>\n<pre><code class=\"language-sql\">DROP USER IF EXISTS 'your_username'@'%';\r\nCREATE USER 'your_username'@'%' IDENTIFIED BY 'your_password';\r\nGRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'%';\r\nFLUSH PRIVILEGES;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Check if the User Exists SELECT user, host FROM mysql.user WHERE user = &#8216;your_username&#8217;; If the user doesn&#8217;t exist, create them first: CREATE USER &#8216;your_username&#8217;@&#8217;%&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[24,56],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql","tag-users"],"_links":{"self":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":0,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}