What are common reasons for receiving a "mysql error: Access denied for user: 'root@localhost' (Using password: NO)" message when attempting to connect to a database in PHP?

This error typically occurs when attempting to connect to a MySQL database without providing a password for the 'root' user. To resolve this issue, ensure that the correct password is provided in the connection settings. Additionally, check that the 'root' user has the necessary privileges to access the database.

<?php
$servername = "localhost";
$username = "root";
$password = "your_password_here";
$dbname = "your_database_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>