写一个连接数据库的 conn.php

<?php
$con = @mysqli_connect('localhost', 'root', '', 'wordpress');

if (!$con) {
    echo "Error: " . mysqli_connect_error();
    exit();
}
echo 'Connected to MySQL';

报错:

Error: The server requested authentication method unknown to the
client

解决:

By default and for some reason, mysql 8 default plugin is auth_socket. Applications will most times expect to log in to your database using a password.

If you have not yet already changed your mysql default authentication plugin, you can do so by:

  1. Log in as root to mysql
  2. Run this sql command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY 'password'; 

Replace 'password' with your root password.

preView