PHP连接MySQL数据库失败Warning: mysqli_connect(): The server requested authentication method unknown to t...

PHP连接mysql报错呀.png

PHP学习中......
MySQL版本 8.0.12
尝试用PHP连接数据库,结果报错报的我很懵啊~

代码如下:

";

$con = mysqli_connect("localhost","root","12345678");
if (!$con)
  {
  die('Could not connect: ' . mysqli_error());
  }
  else{
      echo "mysql connect success!~";
  }

// some code

mysqli_close($con);

查了一下发现是mysql8密码机制换成了cha2导致的,解决办法hin简单,来一个SQL命令:

mysql> ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';

记得改成自己的用户名和密码~搞定!

mysql连接成功.png

hhh 小白的快乐学习

你可能感兴趣的:(PHP连接MySQL数据库失败Warning: mysqli_connect(): The server requested authentication method unknown to t...)