mysql - Access Denied error while using PHP to connect to database in CentOS 7
Get the solution ↓↓↓I am trying to connect to remote MySQL database at address 192.168.43.198. I am using CentOS 7 on both the nodes. my setup is as follows:
Database Node
IP: 192.168.43.198/24
have installed necessary packages for MySQL DB
Enabled necessary services and ports in firewall
Client Node
IP: 192.168.122.73/24
Configured it for hosting a website. Installed httpd, mysql and dependencies.
Enabled necessary services and ports in firewall
I have enabled remote login from mysql_secure_installation command and have fired several queries in mysql which grant every user every permission
grant usage on *.* to DBuser@'%' identified by '123456789';
grant all privileges on *.* to DBuser@'%' identified by '123456789';
flush privileges;
in Client node, when I run the command
mysql -h 192.168.42.198 -u DBuser -p
Enter password: 123456789
I can access the database.
But my client node is also a web-server and when I try to connect to database using php, it is giving permission denied error
/var/www/html/index.html file
<html>
<head>
<title>Node 01</title>
</head>
<body>
<form action="index.php" method="get">
<input type="submit" value="Open DB">
</form>
</body>
</html>
I just have one button which points to the index.php file.
/var/www/html/index.php file
$link = mysqli_connect("192.168.43.198", "DBuser", "123456789","demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
echo 'Connected to the database.<br>';
database demo exists and I can manipulate it through command line as stated above and it works fine but when I click on the button in HTML, I am getting the error "ACCESS DENIED"
ERROR: Could not connect. Permission denied
I am using php 7.0 in Client Node here are the packages I installed in order to get php working
# rpm -qa | grep -i php
php-pdo-5.4.16-46.el7.x86_64
php-mcrypt-5.4.16-7.el7.x86_64
php-mysql-5.4.16-46.el7.x86_64
php-gd-5.4.16-46.el7.x86_64
php-ldap-5.4.16-46.el7.x86_64
php-5.4.16-46.el7.x86_64
php-common-5.4.16-46.el7.x86_64
php-cli-5.4.16-46.el7.x86_64
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.