13

I know there are many people already asked this , but this people mostly forgot password of blocked by firewall which I have none of this situations .

I am developing with php , and I need to connect to remote database to let all my team work on it .

localhost was just going fine , but when I tried to switch it gave me this error

No connection could be made because the target machine actively refused it.

and this is my code where I want to connect to .nf.biz database :

$db=mysqli_connect($host,$user,$password,$db_name,3306);
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
BishoyM
  • 561
  • 1
  • 7
  • 16

11 Answers11

15

Your MySQL server is only accepting connections on *nix socket (/var/run/mysqld/mysqld.sock if you're running Ubuntu) or for localhost only.

You have to edit your my.cnf (on Ubuntu again is located in /etc/mysql/my.cnf) and change the following:

bind-address = 0.0.0.0

And comment out the following

#skip-networking

Finally restart MySQL.

Be careful with that, if your MySQL machine is accessible from public Internet will be accepting connections from everybody!

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
  • 1
    i saw this solution before , but i didn't find bind-address in my.ini !! – BishoyM Mar 29 '14 at 21:04
  • On which OS is MySQL running? – Xavier Rubio Jansana Mar 29 '14 at 21:06
  • am using 8.1 and wamp is my client for apache and mysql – BishoyM Mar 29 '14 at 21:07
  • Ok. Then you have to add it in the [mysqld] section. Also be sure that skip-networking is commented out. – Xavier Rubio Jansana Mar 29 '14 at 21:09
  • this how it looks now [mysqld] bind-address = 0.0.0.0 port=3306 #skip-networking but it still the same problem after restarting wamp – BishoyM Mar 29 '14 at 21:16
  • First of all, are you sure you're restarting MySQL in the process of restarting WAMP? In case of doubt, restart the machine (I know, is lame, but effective). If this doesn't solve the problem, issue a `netstat -ano | find "3306"` in the command line and post the result. – Xavier Rubio Jansana Mar 29 '14 at 21:21
  • 2
    i did restart the machine but nothing happened , and this is the result u required , TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 5420 – BishoyM Mar 29 '14 at 21:40
  • i uploaded the php on web host and it worked perfectly . – BishoyM Mar 29 '14 at 21:41
  • The result is correct, MySQL is listening on all interfaces in the correct port. More things to check: that you're pointing to the correct machine in your PHP code, and more probably, that your user is only valid for localhost. To check the later, you'll have to check that in MySQL permissions your user is show as `youruser@%`, and not `youruser@localhost`. If is the latter, then you'll have to create a new user called `youruser@%`. This is a different user! As so, it will have a different password (you can make it the same as the old one). Also, you'll have to grant it the same permissions. – Xavier Rubio Jansana Mar 29 '14 at 21:47
  • am really sorry but , this time am gonna ask how to do this , i totally don't know where to edit users , and thanks again :) – BishoyM Mar 29 '14 at 22:08
  • Ok. Probably you will have phpMyAdmin installed. Look for "Permissions". Hope I've given you the right direction to look at :) – Xavier Rubio Jansana Mar 29 '14 at 22:18
  • i am using remote mysql database , and after some searching i got this from the remote server after i entered SHOW GRANTS FOR CURRENT_USER; i got this GRANT USAGE ON *.* TO '1388574_project'@'%' IDENTIFIED BY PASSWORD '********' WITH MAX_QUERIES_PER_HOUR 12000 MAX_CONNECTIONS_PER_HOUR 1500 GRANT ALL PRIVILEGES ON `1388574\_project`.* TO '1388574_project'@'%' – BishoyM Mar 29 '14 at 22:21
  • That means that for this server, the user `'1388574_project'@'%'` can connect remotely (not only from localhost) and that has all the privileges on that database. You should do more or less the same for your new server (using GRANT sentence). – Xavier Rubio Jansana Mar 29 '14 at 22:25
  • so after all i will have to turn on include_url and included my database from the web host well it seems the only way , anyway thanks very much man :) – BishoyM Mar 29 '14 at 22:44
  • Had the same issue, found the bind definition in /etc/mysql/mysql.conf.d/mysqld.cnf (MySQL version: 5.7.26-0ubuntu0.16.04.1) – Avi Kehat Sep 08 '19 at 08:58
4

Even if this is not your case, I will add the answer here, because the message for this bug is the same.

There is a bug in MySQL server when you have some alias for localhost in c:\Windows\System32\Drivers\etc\hosts, MySQL server is unable to accept connection to localhost.

Remove the alias and MySQL Server will start to accept connections to localhost.

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
2

I do not have the #skip-networking option.

I resolved it by hashing out the bind address line (See 3rd line below).

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.**
#bind-address       = 127.0.0.1
2

I solved just adding the port in bind-address like that: 127.0.0.1:3388

1

Well this might be late but for future visitors,

I found out back then that biz.nf refuses any connections to it's DB from outside source which means that only the web-apps hosted on biz.nf have the access to their DB other than that you will get rejected.

BishoyM
  • 561
  • 1
  • 7
  • 16
1

Go to services enable the service named after the root user (under the category "Log On As" -> Network Service)

VickyP
  • 21
  • 4
0

I fixed this by setting the bind-address in my.cnf to the server's public IP address:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = SERVER_IP_ADDRESS
user2694130
  • 1
  • 1
  • 1
0

This error occurs when the database is not responding.

I resolve this error by following steps:

  1. Press CTRL+R then type service.msc. A window opens.
  2. Check for MYSQL56 OR MYSQL57, click on that.
  3. NOW on the left bottom corner of the window. click on the expand.
  4. Again window refresh then u can see the start service option.
  5. click on that and the error resolve.

This works for me. hope your error is also resolved. mail me: rkkp1023@gmail.com

rkkp1023
  • 9
  • 1
  • Can you explain that further? I don't think there is any possibility to get into some service manager when using a remote database, as given in this question – Nico Haase May 13 '19 at 15:16
0

Using Wamp (php7) on Windows 10... It is currently working then it suddenly displayed that error. I restarted my laptop and the error is gone...

-1

You have to start you service for the currently active mysql server, like mine was mysql80 so the following steps might help:

start> cmd>run as administrator> sc start mysql80
Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
Suraj
  • 1
  • 1
  • 1
    Can you explain that further? I don't think there is any possibility to get into some service manager when using a remote database, as given in this question – Nico Haase May 13 '19 at 15:17
-2

Your MySQL server is only accepting connections on *nix socket (/var/run/mysqld/mysqld.sock if you're running Ubuntu) or for localhost only.

You have to edit your my.cnf (on Ubuntu again is located in /etc/mysql/my.cnf) and change the following:

bind-address = 0.0.0.0

And comment out the following

#skip-networking

Finally restart MySQL.

Be careful with that, if your MySQL machine is accessible from public Internet will be accepting connections from everybody!

sudo -s
sudo gedit /etc/mysql/my.cnf
bind-address = 0.0.0.0
#skip-networking
save
sudo service mysql restart

Worked perfect!

blackbishop
  • 30,945
  • 11
  • 55
  • 76