Warning: mysqli_connect(): (28000/1045): Access denied for user 'root'@'localhost'

Asked

Viewed 1,009 times

0

I’m making a website, while testing locally this connection code worked

<?php
$servername = "localhost";
$database = "bdcomentarios";
$username = "root";
$password = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
}

$nome = $_POST['nome'];
$email = $_POST['email'];
$comentario = $_POST['comentario'];
$data = date("Y/m/d");


if(strlen($_POST['nome'])) #insere somente se no form foi escrito o nome
{
    $sql = "INSERT INTO tbcomentarios9 (nome, email, data, comentario) VALUES ('$nome', '$email', '$data', '$comentario') ORDER BY id DESC";
if (mysqli_query($conn, $sql)) {
    header('Location: obrigado2.html');
} else {
      echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>

after uploading it to Cpanel, it stopped working and gave the error, "Warning: mysqli_connect(): (28000/1045): Access denied for user 'root'@'localhost'", I already tried to create a user with all permissions and uses, already checked the syntax, and nothing, someone can tell me what’s wrong?

  • means that the table order will be defined by the most recent "id" number (a column of my table)

  • Where did you conclude "means that the order of the table will be defined by the number of "id""? If you want some order while recovering database data then use ORDER BY in SELECT. See the documentation that will make sure that there is no ORDER BY clause in INSERT.

1 answer

1

Hello, I believe that some causes can cause this error, I will inform the ones that I find more common and that can quickly make it work again.

When we install a mysql on some server or even locally it comes with remote access configuration disabled.

To enable simply edit the file my.cnf or the file that gets its confs.

bind-address = 0.0.0.0

Another error that usually happens in cPanel is that your account is out of sync, cPanel and mysql account in the case. Try resetting the password registered in cPanel.

Ord to see if that solves the Issue:

"WHM >> Password Modification"

And lastly if you are using Cpanel check the file: /home/$username/.my.cnf

Usually there are some information, even in the case of root password and things like that, preventing you to change some parameters.

I hope it helped.

  • opa, thank you very much, I found the error, I was using phpmyadmin from my localhost, when I should be using my server’s Cpanel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.