ERROR: Access denied for user 'root'@'localhost' (using password: YES)

Asked

Viewed 5,261 times

0

When I use my form to search in php connection, this error appears:

Access denied for user 'clientes_assoc'@'localhost' (using password: YES)

My connection is like this:

<?php
 $hostdb = "localhost";
 $userdb = "clientes_assoc"; 
 $passdb = "senha";
 $tabledb = "assocs";

$conecta = mysql_connect($hostdb, $userdb, $passdb) or die (mysql_error());
@mysql_select_db($tabledb, $conecta) or die ("Erro ao conectar com o banco de dados");

?>

I do not know how to solve, since the user is with all permissions.

  • Already tested these credentials by creating a connection in a Mysql client?

  • Yes! And I still can’t solve

  • Exchange localhost for 127.0.0.1

  • Is on your computer or is on a website?

  • It’s on a website. and I switched it to 127.0.0.1 and it keeps showing the same thing.

1 answer

0


Hosts, servers, etc., usually do not have the Mysql server on the same machine as Apache (where php is and etc.), this is because usually the stations where the database servers are located are separated, then you must access your Hosting/VPS panel or whatever and check which HOST or IP is your mysql server.

I recommend you read this: What’s the difference between Mysql and phpMyAdmin?

Note that generally even cheaper hosts can have multiple mysql servers, so it would also not make much sense to use localhost as host.

Usually the server uses a domain with its host, for example:

  • Website http: www.site.com
  • Mysql server: msql.site.com

This is just an illustrative example, in general it would be something like:

<?php
$hostdb = "mysql.meuservidor123.com";
$userdb = "clientes_assoc"; 
$passdb = "senha";
$tabledb = "assocs";

$conecta = mysql_connect($hostdb, $userdb, $passdb) or die (mysql_error());

I also recommend not using the prefix API mysql_ she is obsolete, today we have the Apis mysqli and PDO, read about in:

Browser other questions tagged

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