unable to connect o MySQL using PHP via web browser???
Hello to all,
I am just trying to established and TEST a simple to my MySQL test database using PHP via my firefox browser. I am able to connect using SSH and via terminal window on Fedora 20. I have created small php connection file so that I can test the connection. Code:
<?php when I type in my 127.0.0.1/test.php file in my FIREFOX browser. I get a error message " Failed to connect to MySQL: Permission denied " Just trying to understand where I went wrong? any help is greatly appreciated. |
Is this your sample code?
you must replace respective Host_IP address, username, password and databasename Quote:
Quote:
|
Quote:
Yes, I did that. I put in the IP address of the server, username of the mysql user, user password, and the database name. it is still giving me error? Does this have something to do with the mysql.socket file??? |
Is your MySQL server on the same box as your Apache server?
Check that the username you are using has permissions to access the database from the host that Apache is running on. |
Quote:
Yes, MySQL server is on the same box as my Apache server. how do I check the permissions to access the database? what command I have to use? |
http://dev.mysql.com/doc/refman/5.5/en/show-grants.html
[Edit:]Also you may find this handy: Code:
select * from `mysql`.`db`; |
MySQL grants right to users at localhost. For localhost it uses the socket connection. It is most likely that that permission is granted.
But I see you use the domain name to connect. Most likely the domain name is resolved to the IP of your box, say 123.123.123.123. Now this IP is not granted access to the database. Because it is an IP and not localhost. So try to grant permissions to this user to connect from localhost ('*'@localhost) and to connect from all hosts ('*'@'*'). You can test this behaviour on the Bash command line: Code:
mysql -h example.com -u peter -pabc123 mydb Code:
mysql -u peter -pabc123 mydb jlinkels |
Quote:
I did enforce the SELinux policy on my server. Code:
[root@localhost]# setsebool -P httpd_can_network_connect 1 Now I am getting a different error after executing these commands above? Code:
Failed to connect to MySQL: Access denied for user 'user'@'localhost' (using password: YES) when I change the IP address from 127.0.0.1 to 192.168.1.3 on my php script, I get a different error message. I am confused as to what I am doing wrong? Code:
error message : Quote:
|
Quote:
mine looks something like this. Code:
<?php |
Open a terminal window and issue both these commands:
Code:
mysql -h 127.0.0.1 -u peter -pabc123 mydb Code:
mysql -u peter -pabc123 mydb I assume at least of those commands allows you access to the database. If so, while you are connected to the database, issue the command: Code:
show grants; And post the output here. CTRL-C exits you from the database. jlinkels |
Quote:
Code:
mysql -h 127.0.0.1 -u peter -pabc123 mydb Code:
mysql -u peter -pabc123 mydb This command did not work either I was able to get into the MySQL database using : Code:
mysql -u 127.0.0.1 root -pabc123 mydb both commands with ROOT worked. basically, my username (one that I use to login initially to login into desktop) does not have access to MySQL database. All I am trying to do test my php connection to my database via WEB browser. that is why I used that simple $mysql connect script. so that when I create a table or database, I could view using a browser. this is my end goal. output from the SHOW GRANTS; command. Code:
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*0C96AF962992C0897E3FA11FC5BB750ADBC39DA0' WITH GRANT OPTION | hope this is not all confusing. :) |
Quote:
Try this... (as your root user) Code:
GRANT ALL ON mydb.* TO peter@localhost identified by "abc123"; Code:
mysql -u peter -pabc123 mydb |
Have you created a user 'peter' and granted privileges in mysql? Doesn't look like it.
|
Quote:
so before I could not connect using my user account to connect to my database. Thanks to your help. I was able to run the command: Code:
mysql -u user -pabc123 mydb example code: Code:
<?php All I get is a BLANK White Page? At least you helped me get the USER to connect to my DATABASE. thanks, Should I not get the message "connected to MySQL" ? |
Quote:
as per previous poster, I granted privileges to my USER and now I am able to connect via terminal. But my browser still shows BLANK white page when I try to run a sample PHP mysql connect script. Code:
<?php |
All times are GMT -5. The time now is 11:13 AM. |