{"id":92,"date":"2021-08-18T21:26:10","date_gmt":"2021-08-19T02:26:10","guid":{"rendered":"https:\/\/sourceopen.com\/?p=92"},"modified":"2021-08-18T21:36:48","modified_gmt":"2021-08-19T02:36:48","slug":"how-to-fix-it-error-connecting-to-database-sqlstatehy000-2054-the-server-requested-authentication-method-unknown-to-the-client-with-php-and-mysqld","status":"publish","type":"post","link":"https:\/\/sourceopen.com\/index.php\/how-to-fix-it-error-connecting-to-database-sqlstatehy000-2054-the-server-requested-authentication-method-unknown-to-the-client-with-php-and-mysqld\/","title":{"rendered":"How to Fix It: Error connecting to database: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client with PHP and MySQLd"},"content":{"rendered":"\n<p>So you updated MySQLd, or perhaps you just updated your distro, like to Ubuntu 20 LTS or whatever the latest and great flavor of the day is&#8230; And now you keep getting these pesky errors every time you try to use your website.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Error connecting to database: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client<\/pre>\n\n\n\n<p>You know you have the right username and password for your database. You can likely even connect to your db via the mysql command line.<\/p>\n\n\n\n<p>Well, MySQL version 8 has some problems with certain versions of PHP. (For more details you can see this <a href=\"https:\/\/www.php.net\/manual\/en\/mysqli.requirements.php\">post from PHP<\/a>.) MySQL changed the default password type, and older versions of PHP have not adapted to this yet.<\/p>\n\n\n\n<p><strong>The Fix<\/strong><\/p>\n\n\n\n<p>So how do you fix the &#8220;Error connecting to database: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client&#8221; error? Very easy!<\/p>\n\n\n\n<p>Modify your mysqld.cnf file for your MySQLd daemon. This is typically someplace like <em>\/etc\/mysql\/<\/em>. In Ubuntu 20 LTS it is in <em>\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/em><\/p>\n\n\n\n<p><strong>In Ubuntu 20 LTS use the following:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># echo 'default_authentication_plugin=mysql_native_password' >>  \/etc\/mysql\/mysql.conf.d\/mysqld.cnf \n\n# systemctl restart mysql<\/pre>\n\n\n\n<p>The line above uses your shell to append (&gt;&gt;) the correct line to the mysqld.cnf file.<\/p>\n\n\n\n<p><strong>In other linux or *nix distributions:<\/strong><\/p>\n\n\n\n<p>Just edit your mysqld.cnf file and add the following line at the end:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> default_authentication_plugin=mysql_native_password <\/pre>\n\n\n\n<p>Then restart the MySQL server using your system&#8217;s method for doing so. This is often something like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># service mysql restart<\/pre>\n\n\n\n<p>Or perhaps:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># service mysqld restart<\/pre>\n\n\n\n<p>Or sometimes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> \/etc\/init.d\/mysqld restart<\/pre>\n\n\n\n<p>On FreeBSD it would be something like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \/usr\/local\/etc\/rc.d\/mysql-server stop\n# \/usr\/local\/etc\/rc.d\/mysql-server start<\/pre>\n\n\n\n<p>You get the idea, and can always web search for your OS.<\/p>\n\n\n\n<p>Basically this tells MySQL to use the old password style by default and all your old PHP scripts should work just fine again. You will have fixed the  &#8220;Error connecting to database: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client&#8221;<\/p>\n\n\n\n<p>Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you updated MySQLd, or perhaps you just updated your distro, like to Ubuntu 20 LTS or whatever the latest and great flavor of the day is&#8230; And now you keep getting these pesky errors every time you try to &hellip; <a href=\"https:\/\/sourceopen.com\/index.php\/how-to-fix-it-error-connecting-to-database-sqlstatehy000-2054-the-server-requested-authentication-method-unknown-to-the-client-with-php-and-mysqld\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[4,77,76,18,23,16,75,17,78,24],"_links":{"self":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/92"}],"collection":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":5,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/posts\/92\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sourceopen.com\/index.php\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}