如何解决php mysqli_connect: authentication method unknown to the client [caching_sha2_password]的问题?

如何解决php mysqli_connect: authentication method unknown to the client [caching_sha2_password]的问题?

这个是在php5中连接mysql的问题。

在my.ini中添加:default_authentication_plugin=mysql_native_password

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
#default_authentication_plugin=caching_sha2_password
default_authentication_plugin=mysql_native_password
character-set-server = utf8
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION 

然后用下列命令修改密码:

ALTER USER 'mysqlUsername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';

或者新建用户:

 CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

 

发布了444 篇原创文章 · 获赞 13 · 访问量 10万+
展开阅读全文

mysqli :: __ construct():客户端未知的身份验证方法[caching_sha2_password] x [重复]

01-25

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/14612551/mysql-remote-connection-fails-with-unknown-authentication-method" dir="ltr">MySQL remote connection fails with “unknown authentication method”</a> <span class="question-originals-answer-count"> 7 answers </span> </li> <li> <a href="/questions/50026939/php-mysqli-connect-authentication-method-unknown-to-the-client-caching-sha2-pa" dir="ltr">php mysqli_connect: authentication method unknown to the client [caching_sha2_password]</a> <span class="question-originals-answer-count"> 6 answers </span> </li> </ul> </div> <p>I've just installed xampp and I'm running a MySQL db locally on phpMyAdmin. I'm trying to output the contents of a database via a .php doc, but I'm getting two warnings when trying to do so:</p> <p>Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in C:\xampp\htdocs\footfallTracker\test.php on line 20</p> <p>Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in C:\xampp\htdocs\footfallTracker\test.php on line 20 Connection failed: The server requested authentication method unknown to the client</p> <p>Here's the code I'm using:</p> <pre><code> <?php $servername = "localhost"; $username = "root"; $password = "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19"; $dbname = "footfall_tracking"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT ID, Location, Date FROM footstep_count"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "ID: " . $row["ID"]. " - Location: " . $row["Location"]. " - Date: " . $row["Date"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?> </code></pre> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览