I'm having a bit of an issue with a MariaDB I'm running. I'm trying to connect to a database from a PHP page running on a client device, but keep receiving the error message: [Warning] Access denied for user 'rphsp'@'raspberrypi.lan' (using password: YES)
. I've double checked my grants and PHP code and have even tried creating the MariaDB users 'rphsp'@'raspberrypi.lan'
and 'rphsp'@'%'
without any luck. Is there something wrong with the way I've defined the "rphsp" MariaDB user? I'm able to read and write to the same database with that user in a Python script running on the same client device as the PHP page.
I've included all of the information I could think to include below, but please let me know if anything else would be useful. Any ideas or guidance is welcome and please let me know if you have any questions. Thanks in advance!
- Client: raspberrypi.lan (192.168.1.125)
- MariaDB Server: piserver.lan (192.168.1.250)
select host, user, password from mysql.user;
+---------------------------+-------+----------+
| host | user | password |
+---------------------------+-------+----------+
| localhost | root | |
| localhost | pi | |
| 192.168.1.0/255.255.255.0 | rphsp | |
+---------------------------+-------+----------+
show grants for rphsp@'192.168.1.0/255.255.255.0';
+--------------------------------------------------------------------------+
| Grants for rphsp@192.168.1.0/255.255.255.0 |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'rphsp'@'192.168.1.0/255.255.255.0' |
| GRANT ALL PRIVILEGES ON `rphsp`.* TO 'rphsp'@'192.168.1.0/255.255.255.0' |
+--------------------------------------------------------------------------+
<?php
echo "Content from MariaDB";
echo "<br>";
$servername = "piserver.lan";
$username = "rphsp";
$database = "rphsp";
// Create connection
$conn = new mysqli($servername, $username, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
echo "<br>";
$sql = "SELECT * from sensors";
$result = $conn->query($sql);
$conn->close();
?>