0

Connection test php code:

<?php 
$link = mysql_connect('****','****','****'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysql_error()); 
} 
echo 'Connection OK'; mysql_close($link); 
?> 

Error text:

Could not connect to MySQL: A connection can not be established because the target computer expressly denied the connection.

Note: the error text is translated from other language.

MySql configuration file has bind-address = 127.0.0.1 commented and mysql service is restarted.

select user,host from mysql.user; :

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| dev0             | %         |
| debian-sys-maint | localhost |
| mysql.sys        | localhost |
| phpmyadmin       | localhost |
| root             | localhost |
+------------------+-----------+

I acces with dev0 user

Sudo netstat -plunt:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp6       0      0 :::3306                 :::*                    LISTEN      15182/mysqld

Iptables:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
user2983041
  • 1,761
  • 4
  • 19
  • 31
  • 3
    FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Jul 13 '17 at 14:26
  • @JohnConde They are officially removed. You might want to edit your default copy/paste text here :). – Daan Jul 13 '17 at 14:27
  • I also use a mysql connection test online tool and has connection problem. So using that test function I do not think that's the problem, thanks for the info anyway. – user2983041 Jul 13 '17 at 14:29
  • @Daan they are officially deprecated in versions less than 7, where they are officially removed. John is correct here. – Jay Blanchard Jul 13 '17 at 14:29
  • as it is a bit hidden in the other questions: try to set the bind address to 0.0.0.0 - AFAIK 127.0.0.1 is the default in higher mysql versions, so comment masking the line won't be enough. And yes, don't use mysql_* any more – cypherabe Jul 13 '17 at 14:37
  • @JayBlanchard John talks in the present in which they are removed. And you are incorrect by saying "they are officially deprecated in versions less than 7". A correct statement would be "they are officially deprecated in versions less than 7 and higher or equal than PHP 5.5". – Daan Jul 17 '17 at 14:34
  • Pedantic much @Daan? ¯\\_(ツ)_/¯ – Jay Blanchard Jul 17 '17 at 14:36
  • 1
    I could've sworn this was a brad – Funk Forty Niner Jul 17 '17 at 14:40

0 Answers0