How to connect to remote mysql database with php? - php

I have a website and a database on a host. But I want the administrator panel on my laptop? Is it possible connect remotely? How can I do this? Thank you very much!

If I've understood correctly your question, you're looking for a GUI front-end for a remote MySQL database. There's many MySQL front-ends out there, but two I would recommend are the official MySQL Workbench if you're running Windows or Linux, and Sequel Pro if you're running Mac (MySQL Workbench can also run on Mac, but I personally prefer Sequel Pro). Both are free.

The first thing you should try is simply connecting to the remote MySQL server by the command line.
$ mysql -u your_user -h remote.host.name -p
Depending on the output will determine what you need to do next.
Error 1
ERROR 2003 (HY000): Can't connect to MySQL server on 'remote.host.name' (113)
This means that the port is not even open for an external machine to connect to it, so you will need to add whatever port MySQL is running on to your firewall to accept incoming connections.
Error 2
ERROR 1045 (28000): Access denied for user 'your_user'#'your.host.name' (using password: YES)
Assuming that your login credentials are correct, this means that you need to grant permissions from within MySQL. Connecting locally from the remote server, grant permissions like this:
GRANT ALL ON your_database.* TO your_user#'your.host.name' IDENTIFIED BY 'your_password';
Obviously substitute all of the relevant things to what they should be.
When you can connect by command line, connecting by PHP is as simple as using the hostname, username and password information that you used in the mysql command above.

You can use a piece of software called Chive to do this, however it's possible that your server doesn't accept connections remotely.
You can either install Chive locally on your machine and connect to the remote computer, or install Chive remotely and connect to it via HTTP (though I strongly recommend HTTPS).
http://www.chive-project.com/

Wow, just like you connect to the site, you should only change the authentication data if necessary, and external IP mysql.

Related

No connection could be made because the target machine actively

I have installed lamp on linux server 14.0.4, I did not have phpmyadmin there, then I installed phpmyadmin on that server and when I ping on browser like 192.xxx.xx.200/phpmyadmin it opens and brings me the databases.
But when I tried to connect from another system like
mysqli_connect('192.xxx.xx.xx','root','xxxx','xxxx')
It gives me the error
mysqli_connect() [function.mysqli-connect]: [2002] No connection could be made because the target machine actively (trying to connect via tcp://192.xxx.xx.200:3306)
I have searched with Google, but i could not find the solution, but when i tried with the same system like localhost or ip/phpmyadmin it works fine.
MySQL maintains access credentials (usernames / passwords) by machine address as well as username. A new LAMP installation typically doesn't allow anything except local access.
If you issue a command series like this from your local machine you'll get remote access for username from all machines with addresses 192.168.*.*.
CREATE USER 'username'#'192.168.%' IDENTIFIED BY 'password';
GRANT ALL ON * TO 'username'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
PhpMyAdmin has a UI for this.
You can also CREATE USER 'username'#'%' to allow anyone from any machine anywhere to access your server. If you think that's a good idea, go for it. But be careful.

Connect MySQL database behind firewall

There is a server I wish to connect to. It has multiple VMs running on it each VM has a mysql DB. I can currently connect to this server using ssh and then connect to any of the databases from each VM using mysql -u user -h host -p password. Now I want to connect to the same MySQL DBs using MySQL workbench from my local machine. However there is firewall, currently I use putty to get passed the firewall with public private key authentication and I can access any machine I want. I have seen here that I must install a MySQL server locally ( I've done this I am using mysql workbench) and use the loop-back address, in that way you don't need to access an external server. Could anyone point in the right direction on how to do this?
You need to use ssh tunnelling.
In putty under the options go to Connection->SSH->Tunnels. Add a tunnel from source port 13306 to Destination localhost:3306.
You can do this in Putty either before or after you connect. It's best to do beforehand and save the session configuration otherwise it gets tedious having to re-enter the settings.
In MySQL workbench connect to localhost port 13306.
There is a good guide with screen shots here: Setting up an SSH tunnel with PuTTY
An SSH tunnel makes a TCP port on your SSH client machine and directs any traffic to whatever the destination is set to. You can add multiple tunnels, but each one must listen on a different source port number.
You can forward the port via SSH.
ssh -NL is your friend like so:
ssh -NL 3306:localhost:3306 <yourserver>
Then you can point your workbench at localhost.
You don't need any additional software for this task. MySQL Workbench can create SSH tunnels on its own. Watch my tutorial on Youtube how to create connections: https://www.youtube.com/watch?v=DCgRF4KOYIY.
It essentially comes down to creating the right connection type. There is a drop down that allows you to select an SSH connection. Enter the parameters which you used to connect via Putty.

Configuration ODBC for MySQL in Windows

I need help to finish the configuration of ODBC for MySQL in Windows. I am receiving different errors, and I have tried several options, but nothing is working. I really appreciate your help.
So basically, we are using MySQL for CiviCRM on Druppal. In order to access the database online, we use two sets of user/password, one for accessing the phpMyAdmin console, and the other one to access the database itself.
I want to configure the ODBC connection so the users could get the information directly in their computers.
These are the steps that I followed:
I installed the ODBC Driver: "MySQL ODBC 5.3 Driver" 32 bits.
I went to the ODBC administration console and configure one system DNS using this driver.
I get the TCP/IP Server directly from the Database Server Information in our phpMyAdmin, and initially I 3306 port.
I type our user for the database (not for phpMyAdmin) and I tested the connection without password. Although it is successful, I just get the databases: information_schema and test, the name of our database is not in the options.
Later I typed our password, and try the connection again, but I get this error:
"Access denied for user USERNAME#LocalHost (Using password: YES)"
In the console I could see that the username is USERNAME#127.0.0.3 and not localhost.
I tried changing port to 3307 because I read somewhere, that it was a possible solution. But I got this error: Can not connect to MySQL Server on ServerName (10061).
Obviously I am not an expert on this matter. I would appreciate your help to configure effectively the ODBC.
Thanks in advance.
I would get back to port 3306 with a mysql daemon restart.
Run thru some of the tests I typed in here at the bottom under the section Why Can't I connect. Look at hostnames.
and the query select user,host,password from mysql.user. You will also see Grants, etc. The grants suggest why your dbname is not seen. There are always a few moving parts to these problems. The fact that you are on 3307 now adds another wrinkle.

Remote mysql connection issue in PHP

I am creating a remote connection using this PHP script from my website to another website of mine. But it is showing errors which says hostname is not allowed to connect to this MySQL serve
Please let me know what I am missing and also tell me if there any other way to access remote MySQL data using a PHP script.
$connect=mysql_connect("hostname","user","password")or die(mysql_error().'Our database is currently down for updates, please check back later.');
You need to explicitly allow the mysql user to connect from the host. For example CREATE USER 'jeffrey'#'localhost' IDENTIFIED BY 'mypass'; will allow the user jeffrey to connect only from localhost.
You can do that via sql commands or phpmyadmin, check the users tab.
You need to grant the mysql user access to your database from the host where the script is running. So if your mysql server is on host server, and the script runs on machine dev, your grant statement would look something like this:
GRANT ALL PRIVILEGES ON database.* TO 'user'#'dev' IDENTIFIED BY 'password';
Does your MySQL database allow remote access to connect? If not, change the configs.
UPD
Tutorial for changing mysql remote access configs

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