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! :)
Related
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.
I work on a dictionary PHP project. Project owner has a dedicated server. They control server files via terminal. And they have a big database which include 370,000 words. In my program I want to connect to database. But the problem is that they don't want to upload my PHP project files to their server. Because they fear that the database maybe stolen by others. They say you can access our mysql server via some server info and they have send some information like this:
server ip : xx.xxx.xxx.xx
Port=3307;
UID=xxx;
pwd=xxxx
The thing that I know is if I want to connect a remote mysql server, The server owner must allow my IP address or upload project files to their server.
They say we don't have a ftp interface and can't allow remote IPs. You can successfully connect via mysql connector which written in php.
Is it possible to connect to the server only with this server information if the server owner not allow to my IP address for mysql connection?
No, it's not possible (with MySQL server default configuration) to connect to a remote MySQL server instance if your user id does not have permission to connect from the remote IP to MySQL server.
If you try to connect to local MySQL server these information would suffice but if you try to connect to a remote host with these information you might get an error like this:
"Connect failed: Access denied for user 'root'#'aa.bb.cc.dd' (using
password: YES)"
This indicates that your user id does not have permission to connect to the MySQL instance from this remote IP address.
But again you can try to connect to the remote MySQL server and get a connection back. It all depends on the remote MySQL server configuration.
The above information is enough to connect to MySQL server through php.
But if the server owner, has disallowed your IP for MySQL port, then you will not be able to connect.
But maybe that isn't the case, the IP disallowing can be application specific.
eg. they can disallow outside IPs to access there FTP and SSH but their MySQL port can be open for outside IP addresses hence can be accessed by you.
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
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.
I have developed a web application that uses PHP and MySQL and has all been running fine from a single development server. I now want to separate things a bit and place an app server within Amazons cloud that will receive and process uploaded files. The database is going to remain on the dedicated server but will need to be accessed by the EC2 instance.
Heres what I have tried so far...
In phpMyAdmin I added a new user to the privileges table. I gave it the elastic IP address from AWS as the host name, a new password and granted privileges to INSERT, SELECT and UPDATE.
In the PHP scripts on my EC2 based app server I included this username, password and the domain name of the location of the mysql server (example.domain.net) when connecting with mysql_connect
I have a simple test page that tries to SELECT and echo some results from the database but get the following error -
Could not connect to MySQL: Can't connect to MySQL server on 'example.domain.net' (4)
What could this mean, what have I missed, are there any other issues such as trying to do this from within EC2 that will cause other problems?
cheers all
Turns out the only other thing I needed to do was to open port 3306 on the database server to allow access. Did this by going to Control Panel -> Windows Firewall -> Exceptions -> Add Port ["SQL", 3306]
Now it works great!