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

0

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

  

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

My connection looks 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 resolve, since the user has all the permissions.

    
asked by anonymous 12.05.2017 / 20:25

1 answer

0

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

  

I recommend reading this: What's the difference between MySQL and phpMyAdmin?

Note that usually even cheaper hosts can have multiple mySql servers, so it would also not make sense to use localhost as a host.

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

  • Site http: www.site.com
  • mysql server: msql.site.com

This is just an illustrative example, it would usually 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 mysql_ prefix API it is obsolete, today we have the mysqli and PDO APIs, read on at:

12.05.2017 / 21:37