How to access external MySQL from within Vagrant? - php

I would like to access a MySQL database in the public network my host is on.
I need to access the MySQL database from within Vagrant by connecting to the DB via PHP's mysql_connect.
I have an ubuntu/trusty64 Vagrant box running Apache2, PHP and MySQL through the old mysql extension.
When I try to connect to the database on the network via the DB server's IP address, it says Can't connect to database.
What do I need to do to be able to access external servers from within the Vagrant guest?

I could connect properly after all. I just mixed up the variables for my password and the DB name in my code. ^_^;

Related

Configuring MySQL with Node.js from AMP project

I am trying to migrate an existing MySQL + PHP project (with phpMyAdmin) to server-side javascript (Node.js and Express). I am wondering how best to establish a MySQL connection with Node, given that the current setup is on phpMyAdmin? That is, is it possible to configure the node-mysql connection such that it finds the host on phpMyAdmin?
In case the above is not possible, I would like to allow collaborators access to this database. Setting up remote MySQL connections to my localhost MySQL database seems to be one solution, but I have run into difficulty in following this post for two reasons: How to allow remote connection to mysql.
An /etc/mysql folder does not exist on my system (cannot find my.cnf)
Upon granting remote access, I'm unsure how to specify the host and/or ip address for other users that will be connecting remotely to my localhost MySQL db.

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.

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! :)

Linux connecting to mysql 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.

How can I connect to MySQL database on a dedicated Windows 2003 server from EC2 based app server with PHP

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!

Categories