{"id":153,"date":"2018-03-18T17:20:48","date_gmt":"2018-03-18T16:20:48","guid":{"rendered":"http:\/\/test.ekiwi.de\/?p=153"},"modified":"2018-03-18T17:20:48","modified_gmt":"2018-03-18T16:20:48","slug":"hy000-1045-access-denied-for-user","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/index.php\/153\/hy000-1045-access-denied-for-user\/","title":{"rendered":"(HY000\/1045): Access denied for user"},"content":{"rendered":"<p>Fehler bei MySQL-Zugriff trotz richtigen Passwort! Heute geht es um einen interessanten Fehler in Verbindung mit MySQL. Das Problem ist bei der Testinstallation von unserem <a href=\"https:\/\/da-software.de\/software\/da-formmaker\/\" target=\"_blank\">Formmail-Script<\/a> in Xampp aufgefallen.<\/p>\n<p><!--more--><\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/prwaPmGJaQE\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>F\u00fcr die Einrichtung der Datenbank habe ich einen extra Benutzer angelegt. Allerdings kam beim Zugriff auf die Datenbank \u00fcber PHP nur folgende Fehlermeldung:<\/p>\n<pre>\r\nWarning: mysqli_connect(): (HY000\/1045): Access denied for user 'formmail'@'localhost' (using password: YES)\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/03\/mysql_3.png\" alt=\"\" width=\"575\" height=\"281\" class=\"alignnone size-full wp-image-154\" srcset=\"\/wp-content\/uploads\/2018\/03\/mysql_3.png 575w, \/wp-content\/uploads\/2018\/03\/mysql_3-300x147.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<p>Seltsam, das Passwort stimmt und der Account ist in phpMyAdmin korrekt angelegt.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/03\/mysql_1.png\" alt=\"\" width=\"487\" height=\"342\" class=\"alignnone size-full wp-image-157\" srcset=\"\/wp-content\/uploads\/2018\/03\/mysql_1.png 487w, \/wp-content\/uploads\/2018\/03\/mysql_1-300x211.png 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/p>\n<p>Auch im Code gibt es keinen Fehler:<\/p>\n<pre>\r\n$dbname='formmail'; \r\n$dbhost='localhost';\r\n$dbuser='formmail'; \r\n$dbpass='password'; \r\n$db = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);\r\n<\/pre>\n<p>Interessanterweise funktionierte die Verbindung zur Datenbank sobald man statt <code>localhost<\/code> die IP-Adresse verwendete.<\/p>\n<pre>$dbhost='192.168.0.11';<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/03\/mysql_2.png\" alt=\"\" width=\"642\" height=\"249\" class=\"alignnone size-full wp-image-158\" srcset=\"\/wp-content\/uploads\/2018\/03\/mysql_2.png 642w, \/wp-content\/uploads\/2018\/03\/mysql_2-300x116.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/p>\n<p>Was ist da los?<\/p>\n<h2>Die L\u00f6sung?<\/h2>\n<p>Aufmerksame Leser werden im Screenshot oben einen Warnhinweis erkannt haben:<\/p>\n<blockquote><p>A user account allowing any user from localhost to connect is present.<br \/>\nThis will prevent other users from connecting if the host part of<br \/>\ntheir account allows a connection from any (%) host.Documentation<\/p><\/blockquote>\n<p>Unser Benutzer &#8222;formmail&#8220; kann von jedem beliebigen Host zugreifen. Dies ist die Angabe <code>%<\/code>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/03\/mysql_4.png\" alt=\"\" width=\"287\" height=\"184\" class=\"alignnone size-full wp-image-155\" \/><\/p>\n<p>Diese Angabe kollidiert mit dem Benutzer <code>Any<\/code>. Es gibt nun zwei M\u00f6glichkeiten. Die erste ist, man entfernt die beiden Benutzerangaben <code>Any<\/code>. Alternativ \u00e4ndern wir den Benutzer <code>formmail<\/code> ab und erlauben den Zugriff vom <code>localhost<\/code>.<\/p>\n<p>Anschlie\u00dfend funktioniert der Zugriff. Die Benutzerangaben von <code>Any<\/code> k\u00f6nnen \u00fcbrigens gefahrlos entfernt werden, bzw. ist das <a href=\"https:\/\/dba.stackexchange.com\/questions\/5620\/is-this-a-normal-set-of-mysql-privileges\" target=\"_blank\">bzgl. Sicherheit sogar empfohlen<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2018\/03\/mysql_5.png\" alt=\"\" width=\"564\" height=\"407\" class=\"alignnone size-full wp-image-156\" srcset=\"\/wp-content\/uploads\/2018\/03\/mysql_5.png 564w, \/wp-content\/uploads\/2018\/03\/mysql_5-300x216.png 300w, \/wp-content\/uploads\/2018\/03\/mysql_5-90x65.png 90w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/p>","protected":false},"excerpt":{"rendered":"<p>Fehler bei MySQL-Zugriff trotz richtigen Passwort! Heute geht es um einen interessanten Fehler in Verbindung mit MySQL. Das Problem ist<\/p>\n","protected":false},"author":1,"featured_media":159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[12],"tags":[24,25],"class_list":["post-153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-mysql","tag-phpmyadmin"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media\/159"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}