No connection could be made because the target machine actively - php

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.

Related

Prevent database from external access

I have created a home Apache server with MySQL and PHP. I have just created a website that I want to be publicly accessible, majorly for my experimenting. However I just realized that my MySQL server that is running on port 3306, usually my PHP connects to the database on localhost with a username and no password. Can't any other remote PHP script connect to my database and siphon off all the stored data? Does it not put my website in jeopardy? How do I stop remote connections to my database server? I only want the applications on my server(or those that I approve of), to access my database. Forgive me if the wording is bad, I couldn't find any helpful articles on Google.
You can restrict your MySQL server to listen only for localhost connections with bind-address = 127.0.0.1 configuration option as it was suggested in the comments.
If you want to make changes only for this particular user you can check the grants with the following query:
SHOW GRANTS FOR CURRENT_USER;
If it is not restricted only to localhost you can restrict it:
GRANT ALL PRIVILEGES ON *.* TO <username> #'localhost' IDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON *.* TO <username> #'127.0.0.1' IDENTIFIED BY '<password>';
In general, I would recommend adding a password because you can make some other configuration changes in future or run other apps using the same MySQL server. It is better to be safe than sorry.

cant connect opencart to mySQL database

I'm trying to set up opencart for my website, but when I fill in everything for the MySQL database I get this error:
No connection could be made because the target machine actively refused it.
I've tried putting it on localhost, I've tried on 127.0.0.1. when I try on 192.168.1.126 (the database server) it says it can't find the database
the server hosting the PHP site is on 192.168.1.125
I'm very new to SQL, I really don't understand it fully. I'm creating a new database in SQL workbench. and filling in the info I need. How to I fix this error?
My guess is that your DB user is only allowed to access the DB server from 127.0.0.1. You might want to grant additional privileges to it and in your SQL shell run something like
GRANT ALL PRIVILEGES ON *.* To 'your-db-user'#'192.168.1.125'

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

How to connect to remote mysql database with 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.

Categories