{"id":1480,"date":"2023-03-24T22:37:01","date_gmt":"2023-03-24T14:37:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1480"},"modified":"2023-04-28T20:32:18","modified_gmt":"2023-04-28T12:32:18","slug":"php-error-the-server-requested-authentication-method-unknown-to-the-client","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/24\/php-error-the-server-requested-authentication-method-unknown-to-the-client\/","title":{"rendered":"PHP\u9519\u8bef\uff1aThe server requested authentication method unknown to the client"},"content":{"rendered":"<p>\u4f7f\u7528PHP\u8fde\u63a5MySQL 8\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u5982\u6807\u9898\u6240\u793a\u7684\u9519\u8bef\uff1a<\/p>\n<pre><code>SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client<\/code><\/pre>\n<p>\u53d1\u751f\u8fd9\u79cd\u9519\u8bef\uff0c\u662f\u7531\u4e8eMySQL 8\u9ed8\u8ba4\u4f7f\u7528\u4e86\u65b0\u7684\u5bc6\u7801\u9a8c\u8bc1\u63d2\u4ef6\uff1a<code>caching_sha2_password<\/code>\uff0c\u800c\u4e4b\u524d\u7684PHP\u7248\u672c\u4e2d\u6240\u5e26\u7684mysqlnd\u65e0\u6cd5\u652f\u6301\u8fd9\u79cd\u9a8c\u8bc1\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>\u5347\u7ea7PHP\u652f\u6301MySQL 8\u7684\u65b0\u9a8c\u8bc1\u63d2\u4ef6\u3002<\/h2>\n<p>PHP 7.2.8\u548cPHP 7.1.20\u5df2\u7ecf\u53ef\u4ee5\u652f\u6301<code>caching_sha2_password<\/code>\uff0c\u76f4\u63a5\u8fde\u63a5MySQL 8<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7<code>phpinfo()<\/code>\u51fd\u6570\u4e86\u89e3\u5f53\u524d\u5b89\u88c5\u7684PHP\u662f\u5426\u652f\u6301<code>caching_sha2_password<\/code><\/p>\n<h2>\u5728MySQL 8\u4e2d\u521b\u5efa\u6216\u4fee\u6539\u4f7f\u7528caching_sha2_password\u63d2\u4ef6\u7684\u8d26\u6237<\/h2>\n<p>\u5982\u679c\u4e0d\u80fd\u5347\u7ea7PHP\uff0c\u53ef\u4ee5\u5728MySQL 8\u4e2d\u521b\u5efa\uff08\u6216\u4fee\u6539\uff09\u4f7f\u7528<code>caching_sha2_password<\/code>\u63d2\u4ef6\u7684\u8d26\u6237\uff0c\u4f7f\u4e4b\u4f7f\u7528<code>mysql_native_password<\/code>\uff0c\u8fd9\u6837\u5148\u524d\u7248\u672c\u7684PHP\u5373\u53ef\u8fde\u63a5\u4f7f\u7528\u3002<\/p>\n<ul>\n<li>\u5728CREATE USER\u65f6\uff0c\u4f7f\u7528<code>IDENTIFIED WITH xxx_plugin BY &#039;password&#039;<\/code>\uff0c\u6bd4\u5982\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">CREATE USER &#039;native&#039;@&#039;localhost&#039; IDENTIFIED WITH mysql_native_password BY &#039;password!2#4&#039;;<\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528ALTER USER\u4fee\u6539\u5df2\u6709\u8d26\u6237\u7684\u9a8c\u8bc1\u63d2\u4ef6\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">ALTER USER &#039;native&#039;@&#039;localhost&#039; IDENTIFIED WITH mysql_native_password<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code class=\"language-sql\">ALTER USER &#039;native&#039;@&#039;localhost&#039; IDENTIFIED WITH mysql_native_password BY &#039;new_password&#039;;<\/code><\/pre>\n<p>\u91c7\u7528\u524d\u4e00\u79cd\u65b9\u5f0f\uff0c\u8d26\u6237\u7684\u5bc6\u7801\u5c06\u88ab\u6e05\u9664\uff1bBY\u5b50\u53e5\u5c06\u4e3a\u8d26\u6237\u8bbe\u7f6e\u65b0\u7684\u5bc6\u7801\u3002<\/p>\n<ul>\n<li><code>\/etc\/my.cnf<\/code>\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6709\u4e00\u884c\uff1a<\/li>\n<\/ul>\n<pre><code># default-authentication-plugin=mysql_native_password<\/code><\/pre>\n<p>\u8bf7\u5220\u9664\u6ce8\u91ca\u7b26\u53f7<code>#<\/code>\u5e76\u91cd\u65b0\u542f\u52a8mysqld\u4f7f\u4e4b\u751f\u6548\uff0c\u6b64\u540e\u521b\u5efa\u7684\u8d26\u6237\u5747\u9ed8\u8ba4\u4f7f\u7528<code>mysql_native_password<\/code><\/p>\n<p>\u5982\u679c\u5b8c\u6210MySQL Server\u7684\u5b89\u88c5\u4e4b\u540e\uff0c\u5728\u6ca1\u6709\u542f\u52a8\u8fc7mysqld\u670d\u52a1\u7684\u60c5\u51b5\u4e0b\u4fee\u6539<code>\/etc\/my.cnf<\/code>\u914d\u7f6e\uff0c\u90a3\u4e48\u542f\u52a8mysqld\u4e4b\u540e\u521b\u5efa\u7684<code>&#039;root&#039;@&#039;localhost&#039;<\/code>\u8d26\u6237\u4e5f\u662f\u4f7f\u7528<code>mysql_native_password<\/code>\u63d2\u4ef6\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528PHP\u8fde\u63a5MySQL 8\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u5982\u6807\u9898\u6240\u793a\u7684\u9519\u8bef\uff1a SQLSTATE[HY000] [2054] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,333],"tags":[],"class_list":["post-1480","post","type-post","status-publish","format-standard","hentry","category-php-basic","category-install-deploy"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1480"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1480\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}