Linux connecting to mysql PHP - php

I have been trying to connect to mysql all evening using PHP.
I know for a fact the username and password are correct as I have tried 3/4 and I know the permissions are set correctly in the database.
If I remote onto this machine and enter the exact same details into the commandline then i can connect to the database without issue.
The problem only seems to be with MYSQL and PHP.
A little more info:
I am trying to run a PHP app on the same server as the mysql database is on. The user has full grant permissions on the local machine. The error i am receiving is :
Fatal error: Attempt to connect to database kmc_cms on
The server is set so no remote access to mysql is available.

In your question you don't show whether you're trying IP or localhost.
Do a
show grants for <username>;
and see if the connection you're trying is even allowed.

Have you enabled remote access for the user you're trying to connect with in mysql?

I found out the issue. Within the mysql database config file there was an error which resulted in the connection allowing users from local host access only. Even though the PHP scripts were connecting using localhost it just would not authenticate. Hence I could log in using command line and not using PHP or other applications.

Related

No connection (#2002) Error connecting to MySQL DB from one IP, but works from another IP

I have a LAMP server hosted on Amzaon AWS and using php to connect and insert values to a MySQL DB on that remote server. (https://studio.hamlethub.com/belocal/final.php)
When I access this form from my office, everything works perfectly. However, from my home, I am receiving an error: No connection (#2002).
I am able to access phpmyadmin successfully from both places, both IP's. I checked the error log and do not see any issues.
What could it be inside of my php that could prevent a successful connection based on the local IP, when I am not using a local server?
Ken
There was an IP in the connection request. I am using PHP form builder which has a setting in the db-connect.php file which needed to be customized.

retrieve data from mysql database using php from a different computer

I am a newbie on PHP . Can someone tell me how to connect and retrieve data from mysql database server using PHP from a different computer.
First of all, the MySQL server must accept remote connections.
Also MySQL's user that you use, must be allowed to log from PHP computer's IP.
Then you can simply connect from your PHP server changing configuration of connection by setting host parameter to MySQL server's IP instead of localhost.
Google for mysql remote connection in order to find information about how to configure it to accept remote connections.
Localhost in name suggest locally , you cannot access mysql database from another computer .
Copy the file and install , only then it will work.

Laravel Artisan: Using a remote database

I am using Laravel 5.1, trying to run php artisan migrate on my local computer. I have my .env file set up with the credentials of a remote database.
However, upon running, I get an error (replaced real details for security):
Access denied for user 'user'#'44.55.66.77' to database 'db_laravel'
It appears that for some reason, it is attempting to run the command on my local IP, which is 44.55.66.77 instead of the remote database. I have already tried allowing remote access to the database from my IP, however I am still having the same issue.
I have also already attempted to connect to the database using its IP, to no avail.
Thanks in advance for your help!
Update: Okay, I read some of my host's documentation, and tried using % as a wildcard to allow any IP access to the database. I now get Access denied for user 'user'#'%' to database 'db_laravel'. However, still not sure what is going on.
This "'user'#'44.55.66.77'" means that user is connecting FROM ip "44.55.66.77", not TO "44.55.66.77".
So I solved the issue. It was a problem with my host not properly accepting the IP I entered for allowing remote access. All is well now. Thanks for all your help!

Cannot access MySQL database from my website, but can access via browser?

I'm trying to hook up my website to my MySQL database on my new webhost, and I'm running into a few issues I can't resolve.
If I navigate to mywebsite.com/phpmyadmin/, I'm presented with an HTTP authorization, and upon successful entry of that, my PHPMyAdmin login page, where I can log-in as my user and see my databases. Yet, if I try to connect via PHP through my website, I receive the error:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mywebsite.com/phpmyadmin' (11)
My connection info is:
$this->dbh = new PDO('mysql:host=mywebsite.com/phpmyadmin;dbname=mydb;charset=utf8','me','myPassword');
I'm running LAMP on Ubuntu 14. Is there any particular reason this is failing?
PHPMyAdmin is a database client application, not a database server.
You need to provide connection information to your database server (which will probably be localhost)
You need to connect to the mysql server rather than the phpMyAdmin interface (won't work).
In this case it's you will use localhost (Really). Why? because localhost just points to the server's local IP. You can also point it to any hostname which points to the server's IP so it knows which server to connect to! :)

How to setup Windows Server 2008 for MySQL remote database connectivity?

I am very new to this server setup and database connectivity. I googled a lot but couldn't find the solution for it.I am developing an android application which needs to post data to remote database. Which is done.
Now i have to setup MySQL Database in the new Windows Server 2008. I have installed and managed to get access the root user(Which is fine). Now i want to access this database from my local computer[Which is iMac]. I already set the privileges by following this link. When i tried to run from my web application it shows the following error.
Error: unable to connect to database. Host 'xx.xx.xxx.x' is not allowed to connect to this MySQL server
Here is my questions
1.) How to get access to the remote MySQL database from any computer?
2.) How to run the web application in the server?Like Web Hosting i.e Do i need to setup ftp account and put the stuff over there?(For Eg: testhost.com/connecttodatabase.php by executing this it will execute whatever code in testhost server. But i have no idea how to do that for my server).
Any help is much appreciated.
Alternately, You can also try...
use the_database_name;
GRANT ALL PRIVILEGES ON
the_database_name.*
TO
'the_user_in_php_code'#'%'
IDENTIFIED BY
'password_of_the_user_in_php_code';
FLUSH PRIVILEGES;
source:
http://forums.devshed.com/mysql-help-4/host-is-not-allowed-to-connect-to-this-mysql-server-366908.html

Categories