connect(): Access denied for user 'root'

Guys i'm having common issue. I want to display data from MySQL database into HTML page using PHP.

Using this code:

<html>
<head>

<title>Pulse Sensor Data </title>

</head>
<body>

<?php

$servername = 'localhost'; 
$username = 'root';  
$password = '';

// Connect to database server
mysql_connect('192.168.1.106','root','','database') or die (mysql_error ());

// Select database
mysql_select_db('database') or die(mysql_error());

// SQL query
$strSQL = "SELECT * FROM pulsesensor";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {

   // Write the value of the column id and value
  echo $row['id'] . " " . $row['value'] . "<br />";

  }

// Close the database connection
mysql_close();
?>

</body>
</html>

but i got

mysql_connect(): Access denied for user 'root'@'XXX' (using password: NO) in C:xampphtdocshtml.php on line 16 Access denied for user 'root'@'Dell' (using password: NO)

i changed the password the same error appear

mysql_connect(): Access denied for user 'root'@'XXX' (using password: YES) in C:xampphtdocshtml.php on line 16 Access denied for user 'root'@'Dell' (using password: YES)

i don't know what to do


Your connection string is using the ip address and root is not configured to access via the ip address you are using for the host. You will have to change it to localhost or add that permission to your mysql server for the root user.

I would suggest that you not do that, but create a new mysql user for your development.

Also, from @sidyll you will not want to use the mysql_* functions and use PDO functions instead.


尝试这个:

mysql_connect($servername,'root','','database') or die (mysql_error ());
链接地址: http://www.djcxy.com/p/69292.html

上一篇: 如何删除MySQL根密码

下一篇: 连接():访问拒绝用户'root'